Duration maps configuration directive to a time.Duration variable. Directive must be in form 'name duration' where duration is any string accepted by time.ParseDuration. As an additional requirement, result of time.ParseDuration must not be negative. Note that for convenience, if directive does ha
(name string, inheritGlobal, required bool, defaultVal time.Duration, store *time.Duration)
| 200 | // |
| 201 | // See Map.Custom for description of arguments. |
| 202 | func (m *Map) Duration(name string, inheritGlobal, required bool, defaultVal time.Duration, store *time.Duration) { |
| 203 | m.Custom(name, inheritGlobal, required, func() (interface{}, error) { |
| 204 | return defaultVal, nil |
| 205 | }, func(_ *Map, node Node) (interface{}, error) { |
| 206 | if len(node.Children) != 0 { |
| 207 | return nil, NodeErr(node, "can't declare block here") |
| 208 | } |
| 209 | if len(node.Args) == 0 { |
| 210 | return nil, NodeErr(node, "at least one argument is required") |
| 211 | } |
| 212 | |
| 213 | durationStr := strings.Join(node.Args, "") |
| 214 | dur, err := time.ParseDuration(durationStr) |
| 215 | if err != nil { |
| 216 | return nil, NodeErr(node, "%v", err) |
| 217 | } |
| 218 | |
| 219 | if dur < 0 { |
| 220 | return nil, NodeErr(node, "duration must not be negative") |
| 221 | } |
| 222 | |
| 223 | return dur, nil |
| 224 | }, store) |
| 225 | } |
| 226 | |
| 227 | func ParseDataSize(s string) (int, error) { |
| 228 | if len(s) == 0 { |