mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 12:27:37 +03:00
32 lines
612 B
Go
32 lines
612 B
Go
package badoption
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/sagernet/sing/common/json"
|
|
"github.com/sagernet/sing/common/json/badoption/internal/my_time"
|
|
)
|
|
|
|
type Duration time.Duration
|
|
|
|
func (d Duration) Build() time.Duration {
|
|
return time.Duration(d)
|
|
}
|
|
|
|
func (d Duration) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal((time.Duration)(d).String())
|
|
}
|
|
|
|
func (d *Duration) UnmarshalJSON(bytes []byte) error {
|
|
var value string
|
|
err := json.Unmarshal(bytes, &value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
duration, err := my_time.ParseDuration(value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*d = Duration(duration)
|
|
return nil
|
|
}
|