From 15738813a09db5c8e5b60a19d67d3f9bd38da3a4 Mon Sep 17 00:00:00 2001 From: Travis Jeffery Date: Sat, 5 May 2018 21:38:06 -0400 Subject: [PATCH] Add GetInt32 --- viper.go | 6 ++++++ viper_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/viper.go b/viper.go index e9966ba..907a102 100644 --- a/viper.go +++ b/viper.go @@ -682,6 +682,12 @@ func (v *Viper) GetInt(key string) int { 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. func GetInt64(key string) int64 { return v.GetInt64(key) } func (v *Viper) GetInt64(key string) int64 { diff --git a/viper_test.go b/viper_test.go index c93480e..60543f5 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1068,6 +1068,10 @@ func TestMergeConfig(t *testing.T) { 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) { t.Fatalf("int64 lagrenum != 765432101234567, = %d", pop) } @@ -1092,6 +1096,10 @@ func TestMergeConfig(t *testing.T) { 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) { t.Fatalf("int64 lagrenum != 7654321001234567, = %d", pop) }