mirror of
https://github.com/spf13/viper
synced 2025-05-07 04:37:20 +00:00
Merge d1bdae2e98
into 907c19d40d
This commit is contained in:
commit
6532c4a9b9
1 changed files with 10 additions and 2 deletions
12
viper.go
12
viper.go
|
@ -658,6 +658,8 @@ func (v *Viper) Get(key string) interface{} {
|
|||
return cast.ToDuration(val)
|
||||
case []string:
|
||||
return cast.ToStringSlice(val)
|
||||
case []int:
|
||||
return cast.ToIntSlice(val)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -705,6 +707,12 @@ func (v *Viper) GetInt32(key string) int32 {
|
|||
return cast.ToInt32(v.Get(key))
|
||||
}
|
||||
|
||||
// GetIntSlice returns the value associated with the key as an integer slice.
|
||||
func GetIntSlice(key string) []int { return v.GetIntSlice(key) }
|
||||
func (v *Viper) GetIntSlice(key string) []int {
|
||||
return cast.ToIntSlice(v.Get(key))
|
||||
}
|
||||
|
||||
// GetInt64 returns the value associated with the key as an integer.
|
||||
func GetInt64(key string) int64 { return v.GetInt64(key) }
|
||||
func (v *Viper) GetInt64(key string) int64 {
|
||||
|
@ -948,7 +956,7 @@ func (v *Viper) find(lcaseKey string) interface{} {
|
|||
return cast.ToInt(flag.ValueString())
|
||||
case "bool":
|
||||
return cast.ToBool(flag.ValueString())
|
||||
case "stringSlice":
|
||||
case "stringSlice", "intSlice":
|
||||
s := strings.TrimPrefix(flag.ValueString(), "[")
|
||||
s = strings.TrimSuffix(s, "]")
|
||||
res, _ := readAsCSV(s)
|
||||
|
@ -1017,7 +1025,7 @@ func (v *Viper) find(lcaseKey string) interface{} {
|
|||
return cast.ToInt(flag.ValueString())
|
||||
case "bool":
|
||||
return cast.ToBool(flag.ValueString())
|
||||
case "stringSlice":
|
||||
case "stringSlice", "intSlice":
|
||||
s := strings.TrimPrefix(flag.ValueString(), "[")
|
||||
s = strings.TrimSuffix(s, "]")
|
||||
res, _ := readAsCSV(s)
|
||||
|
|
Loading…
Add table
Reference in a new issue