mirror of
https://github.com/spf13/viper
synced 2024-12-22 11:37:02 +00:00
Add viper.GetDuration
This commit is contained in:
parent
90734830d1
commit
ededa04e0b
2 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
7
viper.go
7
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))
|
||||
|
|
Loading…
Reference in a new issue