summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-03-03 08:14:11 -0500
committerDave Henderson <dhenderson@gmail.com>2018-03-03 08:31:15 -0500
commit034dfcd90fe7dc353fe0a4d8588d5ed4f40aae85 (patch)
tree3863e5fc9fb3e8ec9b7bd1755954b115f9f03359 /vendor/github.com/mitchellh/mapstructure/decode_hooks.go
parent387a5a45b4c3876ae59d6f9426529b1e7c31bba5 (diff)
Updating vendored dependencies
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'vendor/github.com/mitchellh/mapstructure/decode_hooks.go')
-rw-r--r--vendor/github.com/mitchellh/mapstructure/decode_hooks.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/mapstructure/decode_hooks.go b/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
index afcfd5ee..2a727575 100644
--- a/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
+++ b/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
@@ -115,6 +115,25 @@ func StringToTimeDurationHookFunc() DecodeHookFunc {
}
}
+// StringToTimeHookFunc returns a DecodeHookFunc that converts
+// strings to time.Time.
+func StringToTimeHookFunc(layout string) DecodeHookFunc {
+ return func(
+ f reflect.Type,
+ t reflect.Type,
+ data interface{}) (interface{}, error) {
+ if f.Kind() != reflect.String {
+ return data, nil
+ }
+ if t != reflect.TypeOf(time.Time{}) {
+ return data, nil
+ }
+
+ // Convert it by parsing
+ return time.Parse(layout, data.(string))
+ }
+}
+
// WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to
// the decoder.
//