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
1 changed files with 7 additions and 3 deletions

View File

@ -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))
}