Fix missing marshal for udp_timeout

This commit is contained in:
世界 2023-12-26 10:51:39 +08:00
parent 3eed614dea
commit f5bb5cf343
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -145,12 +145,16 @@ type ListenOptions struct {
type UDPTimeoutCompat Duration 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 var valueNumber int64
err := json.Unmarshal(data, &valueNumber) err := json.Unmarshal(data, &valueNumber)
if err == nil { if err == nil {
*u = UDPTimeoutCompat(time.Second * time.Duration(valueNumber)) *c = UDPTimeoutCompat(time.Second * time.Duration(valueNumber))
return nil return nil
} }
return json.Unmarshal(data, (*Duration)(u)) return json.Unmarshal(data, (*Duration)(c))
} }