Add GetInt32

This commit is contained in:
Travis Jeffery 2018-05-05 21:38:06 -04:00
parent 0967fc9ace
commit 67e97e6c5c
2 changed files with 15 additions and 1 deletions

View file

@ -53,7 +53,7 @@ func init() {
type remoteConfigFactory interface { type remoteConfigFactory interface {
Get(rp RemoteProvider) (io.Reader, error) Get(rp RemoteProvider) (io.Reader, error)
Watch(rp RemoteProvider) (io.Reader, error) Watch(rp RemoteProvider) (io.Reader, error)
WatchChannel(rp RemoteProvider)(<-chan *RemoteResponse, chan bool) WatchChannel(rp RemoteProvider) (<-chan *RemoteResponse, chan bool)
} }
// RemoteConfig is optional, see the remote package // RemoteConfig is optional, see the remote package
@ -661,6 +661,12 @@ func (v *Viper) GetInt(key string) int {
return cast.ToInt(v.Get(key)) return cast.ToInt(v.Get(key))
} }
// GetInt32 returns the value associated with the key as an integer.
func GetInt32(key string) int32 { return v.GetInt32(key) }
func (v *Viper) GetInt32(key string) int32 {
return cast.ToInt32(v.Get(key))
}
// GetInt64 returns the value associated with the key as an integer. // GetInt64 returns the value associated with the key as an integer.
func GetInt64(key string) int64 { return v.GetInt64(key) } func GetInt64(key string) int64 { return v.GetInt64(key) }
func (v *Viper) GetInt64(key string) int64 { func (v *Viper) GetInt64(key string) int64 {

View file

@ -883,6 +883,10 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("lagrenum != 765432101234567, = %d", pop) t.Fatalf("lagrenum != 765432101234567, = %d", pop)
} }
if pop := v.GetInt32("hello.pop"); pop != int32(37890) {
t.Fatalf("pop != 37890, = %d", pop)
}
if pop := v.GetInt64("hello.lagrenum"); pop != int64(765432101234567) { if pop := v.GetInt64("hello.lagrenum"); pop != int64(765432101234567) {
t.Fatalf("int64 lagrenum != 765432101234567, = %d", pop) t.Fatalf("int64 lagrenum != 765432101234567, = %d", pop)
} }
@ -907,6 +911,10 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("lagrenum != 7654321001234567, = %d", pop) t.Fatalf("lagrenum != 7654321001234567, = %d", pop)
} }
if pop := v.GetInt32("hello.pop"); pop != int32(45000) {
t.Fatalf("pop != 45000, = %d", pop)
}
if pop := v.GetInt64("hello.lagrenum"); pop != int64(7654321001234567) { if pop := v.GetInt64("hello.lagrenum"); pop != int64(7654321001234567) {
t.Fatalf("int64 lagrenum != 7654321001234567, = %d", pop) t.Fatalf("int64 lagrenum != 7654321001234567, = %d", pop)
} }