fs: Add string alternatives for setting options over the rc
Before this change options were read and set in native format. This means for example nanoseconds for durations or an integer for enumerated types, which isn't very convenient for humans. This change enables these types to be set with a string with the syntax as used in the command line instead, so `"10s"` rather than `10000000000` or `"DEBUG"` rather than `8` for log level.
This commit is contained in:
parent
e32f08f37b
commit
ae3963e4b4
17 changed files with 516 additions and 20 deletions
|
@ -196,6 +196,14 @@ func (d Duration) Type() string {
|
|||
return "Duration"
|
||||
}
|
||||
|
||||
// UnmarshalJSON makes sure the value can be parsed as a string or integer in JSON
|
||||
func (d *Duration) UnmarshalJSON(in []byte) error {
|
||||
return UnmarshalJSONFlag(in, d, func(i int64) error {
|
||||
*d = Duration(i)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Scan implements the fmt.Scanner interface
|
||||
func (d *Duration) Scan(s fmt.ScanState, ch rune) error {
|
||||
token, err := s.Token(true, nil)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue