StringToTimeHookFunc returns a DecodeHookFunc that converts strings to time.Time.
(layout string)
| 185 | // StringToTimeHookFunc returns a DecodeHookFunc that converts |
| 186 | // strings to time.Time. |
| 187 | func StringToTimeHookFunc(layout string) DecodeHookFunc { |
| 188 | return func( |
| 189 | f reflect.Type, |
| 190 | t reflect.Type, |
| 191 | data interface{}) (interface{}, error) { |
| 192 | if f.Kind() != reflect.String { |
| 193 | return data, nil |
| 194 | } |
| 195 | if t != reflect.TypeOf(time.Time{}) { |
| 196 | return data, nil |
| 197 | } |
| 198 | |
| 199 | // Convert it by parsing |
| 200 | return time.Parse(layout, data.(string)) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to |
| 205 | // the decoder. |
no outgoing calls
searching dependent graphs…