Set a new value on the option. Setting a negative duration value will cause an error to be returned.
(s string)
| 14 | // Set a new value on the option. Setting a negative duration value will cause |
| 15 | // an error to be returned. |
| 16 | func (d *PositiveDurationOpt) Set(s string) error { |
| 17 | err := d.DurationOpt.Set(s) |
| 18 | if err != nil { |
| 19 | return err |
| 20 | } |
| 21 | if *d.DurationOpt.value < 0 { |
| 22 | return errors.New("duration cannot be negative") |
| 23 | } |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | // DurationOpt is an option type for time.Duration that uses a pointer. This |
| 28 | // allows us to get nil values outside, instead of defaulting to 0 |