9 // Duration is time.Duration but looks like "12s" in JSON, rather than
10 // a number of nanoseconds.
11 type Duration time.Duration
13 // UnmarshalJSON implements json.Unmarshaler
14 func (d *Duration) UnmarshalJSON(data []byte) error {
16 return d.Set(string(data[1 : len(data)-1]))
18 return fmt.Errorf("duration must be given as a string like \"600s\" or \"1h30m\"")
21 // MarshalJSON implements json.Marshaler
22 func (d *Duration) MarshalJSON() ([]byte, error) {
23 return json.Marshal(d.String())
26 // String implements fmt.Stringer
27 func (d Duration) String() string {
28 return time.Duration(d).String()
31 // Duration returns a time.Duration
32 func (d Duration) Duration() time.Duration {
33 return time.Duration(d)
36 // Value implements flag.Value
37 func (d *Duration) Set(s string) error {
38 dur, err := time.ParseDuration(s)