From 445d29ddaa4761a725aad51ae89a7bbac548650d Mon Sep 17 00:00:00 2001 From: M Date: Mon, 2 Apr 2018 12:49:05 -0400 Subject: [PATCH] Adds Getter and related code for IntSlices --- viper.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/viper.go b/viper.go index f657b20..178a6eb 100644 --- a/viper.go +++ b/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 {