MCPcopy
hub / github.com/mitchellh/mapstructure / StringToTimeDurationHookFunc

Function StringToTimeDurationHookFunc

decode_hooks.go:124–139  ·  view source on GitHub ↗

StringToTimeDurationHookFunc returns a DecodeHookFunc that converts strings to time.Duration.

()

Source from the content-addressed store, hash-verified

122// StringToTimeDurationHookFunc returns a DecodeHookFunc that converts
123// strings to time.Duration.
124func StringToTimeDurationHookFunc() DecodeHookFunc {
125 return func(
126 f reflect.Type,
127 t reflect.Type,
128 data interface{}) (interface{}, error) {
129 if f.Kind() != reflect.String {
130 return data, nil
131 }
132 if t != reflect.TypeOf(time.Duration(5)) {
133 return data, nil
134 }
135
136 // Convert it by parsing
137 return time.ParseDuration(data.(string))
138 }
139}
140
141// StringToIPHookFunc returns a DecodeHookFunc that converts
142// strings to net.IP

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…