浏览代码

Fix missing marshal for `udp_timeout`

世界 1 年之前
父节点
当前提交
f5bb5cf343
共有 1 个文件被更改,包括 7 次插入3 次删除
  1. 7 3
      option/inbound.go

+ 7 - 3
option/inbound.go

@@ -145,12 +145,16 @@ type ListenOptions struct {
 
 type UDPTimeoutCompat Duration
 
-func (u *UDPTimeoutCompat) UnmarshalJSON(data []byte) error {
+func (c UDPTimeoutCompat) MarshalJSON() ([]byte, error) {
+	return json.Marshal((time.Duration)(c).String())
+}
+
+func (c *UDPTimeoutCompat) UnmarshalJSON(data []byte) error {
 	var valueNumber int64
 	err := json.Unmarshal(data, &valueNumber)
 	if err == nil {
-		*u = UDPTimeoutCompat(time.Second * time.Duration(valueNumber))
+		*c = UDPTimeoutCompat(time.Second * time.Duration(valueNumber))
 		return nil
 	}
-	return json.Unmarshal(data, (*Duration)(u))
+	return json.Unmarshal(data, (*Duration)(c))
 }