DataSize maps configuration directive to a int variable, representing data size. Syntax requires unit suffix to be added to the end of string to specify data unit and allows multiple arguments (they will be added together). See Map.Custom for description of arguments.
(name string, inheritGlobal, required bool, defaultVal int64, store *int64)
| 286 | // |
| 287 | // See Map.Custom for description of arguments. |
| 288 | func (m *Map) DataSize(name string, inheritGlobal, required bool, defaultVal int64, store *int64) { |
| 289 | m.Custom(name, inheritGlobal, required, func() (interface{}, error) { |
| 290 | return defaultVal, nil |
| 291 | }, func(_ *Map, node Node) (interface{}, error) { |
| 292 | if len(node.Children) != 0 { |
| 293 | return nil, NodeErr(node, "can't declare block here") |
| 294 | } |
| 295 | if len(node.Args) == 0 { |
| 296 | return nil, NodeErr(node, "at least one argument is required") |
| 297 | } |
| 298 | |
| 299 | durationStr := strings.Join(node.Args, " ") |
| 300 | dur, err := ParseDataSize(durationStr) |
| 301 | if err != nil { |
| 302 | return nil, NodeErr(node, "%v", err) |
| 303 | } |
| 304 | |
| 305 | return int64(dur), nil |
| 306 | }, store) |
| 307 | } |
| 308 | |
| 309 | func ParseBool(s string) (bool, error) { |
| 310 | switch strings.ToLower(s) { |
no test coverage detected