diff --git a/viper.go b/viper.go index a2633b0..e5a360a 100644 --- a/viper.go +++ b/viper.go @@ -551,6 +551,12 @@ func (v *Viper) GetInt(key string) int { return cast.ToInt(v.Get(key)) } +// 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 { + return cast.ToInt64(v.Get(key)) +} + // Returns the value associated with the key as a float64 func GetFloat64(key string) float64 { return v.GetFloat64(key) } func (v *Viper) GetFloat64(key string) float64 { diff --git a/viper_test.go b/viper_test.go index 858caff..aa9d7fe 100644 --- a/viper_test.go +++ b/viper_test.go @@ -763,6 +763,7 @@ func TestSub(t *testing.T) { var yamlMergeExampleTgt = []byte(` hello: pop: 37890 + lagrenum: 765432101234567 world: - us - uk @@ -773,6 +774,7 @@ hello: var yamlMergeExampleSrc = []byte(` hello: pop: 45000 + lagrenum: 7654321001234567 universe: - mw - ad @@ -790,6 +792,14 @@ func TestMergeConfig(t *testing.T) { t.Fatalf("pop != 37890, = %d", pop) } + if pop := v.GetInt("hello.lagrenum"); pop != 765432101234567 { + t.Fatalf("lagrenum != 765432101234567, = %d", pop) + } + + if pop := v.GetInt64("hello.lagrenum"); pop != int64(765432101234567) { + t.Fatalf("int64 lagrenum != 765432101234567, = %d", pop) + } + if world := v.GetStringSlice("hello.world"); len(world) != 4 { t.Fatalf("len(world) != 4, = %d", len(world)) } @@ -806,6 +816,14 @@ func TestMergeConfig(t *testing.T) { t.Fatalf("pop != 45000, = %d", pop) } + if pop := v.GetInt("hello.lagrenum"); pop != 7654321001234567 { + t.Fatalf("lagrenum != 7654321001234567, = %d", pop) + } + + if pop := v.GetInt64("hello.lagrenum"); pop != int64(7654321001234567) { + t.Fatalf("int64 lagrenum != 7654321001234567, = %d", pop) + } + if world := v.GetStringSlice("hello.world"); len(world) != 4 { t.Fatalf("len(world) != 4, = %d", len(world)) }