From f5bb5cf3437ef76fd1d3d1d9aa31e40a4331b436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 26 Dec 2023 10:51:39 +0800 Subject: [PATCH] Fix missing marshal for `udp_timeout` --- option/inbound.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/option/inbound.go b/option/inbound.go index dd099ff9..ede15944 100644 --- a/option/inbound.go +++ b/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)) }