From ededa04e0bbab359f4dfd31352e39d7c8b200950 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 18 Feb 2015 19:03:20 -0800 Subject: [PATCH] Add viper.GetDuration --- README.md | 1 + viper.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index a06bedb..9f236b2 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ The following functions and methods exist: * GetStringMapString(key string) : map[string]string * GetStringSlice(key string) : []string * GetTime(key string) : time.Time + * GetDuration(key string) : time.Duration * IsSet(key string) : bool One important thing to recognize is that each Get function will return diff --git a/viper.go b/viper.go index dda7091..e808887 100644 --- a/viper.go +++ b/viper.go @@ -267,6 +267,8 @@ func (v *viper) Get(key string) interface{} { return cast.ToFloat64(val) case time.Time: return cast.ToTime(val) + case time.Duration: + return cast.ToDuration(val) case []string: return val } @@ -298,6 +300,11 @@ func (v *viper) GetTime(key string) time.Time { return cast.ToTime(v.Get(key)) } +func GetDuration(key string) time.Duration { return v.GetDuration(key) } +func (v *viper) GetDuration(key string) time.Duration { + return cast.ToDuration(v.Get(key)) +} + func GetStringSlice(key string) []string { return v.GetStringSlice(key) } func (v *viper) GetStringSlice(key string) []string { return cast.ToStringSlice(v.Get(key))