Add viper.GetDuration

This commit is contained in:
Chance Zibolski 2015-02-18 19:03:20 -08:00
parent 90734830d1
commit ededa04e0b
2 changed files with 8 additions and 0 deletions

View File

@ -212,6 +212,7 @@ The following functions and methods exist:
* GetStringMapString(key string) : map[string]string * GetStringMapString(key string) : map[string]string
* GetStringSlice(key string) : []string * GetStringSlice(key string) : []string
* GetTime(key string) : time.Time * GetTime(key string) : time.Time
* GetDuration(key string) : time.Duration
* IsSet(key string) : bool * IsSet(key string) : bool
One important thing to recognize is that each Get function will return One important thing to recognize is that each Get function will return

View File

@ -267,6 +267,8 @@ func (v *viper) Get(key string) interface{} {
return cast.ToFloat64(val) return cast.ToFloat64(val)
case time.Time: case time.Time:
return cast.ToTime(val) return cast.ToTime(val)
case time.Duration:
return cast.ToDuration(val)
case []string: case []string:
return val return val
} }
@ -298,6 +300,11 @@ func (v *viper) GetTime(key string) time.Time {
return cast.ToTime(v.Get(key)) 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 GetStringSlice(key string) []string { return v.GetStringSlice(key) }
func (v *viper) GetStringSlice(key string) []string { func (v *viper) GetStringSlice(key string) []string {
return cast.ToStringSlice(v.Get(key)) return cast.ToStringSlice(v.Get(key))