StringToTimeDurationHookFunc returns a DecodeHookFunc that converts strings to time.Duration.
()
| 122 | // StringToTimeDurationHookFunc returns a DecodeHookFunc that converts |
| 123 | // strings to time.Duration. |
| 124 | func 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 |
no outgoing calls
searching dependent graphs…