mirror of https://github.com/spf13/viper.git
Add viper.GetDuration
This commit is contained in:
parent
6c5a915341
commit
988f859eff
|
@ -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
|
||||||
|
|
7
viper.go
7
viper.go
|
@ -258,6 +258,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
|
||||||
}
|
}
|
||||||
|
@ -289,6 +291,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))
|
||||||
|
|
Loading…
Reference in New Issue