mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Add GetInt64
This commit is contained in:
parent
6d2589cd85
commit
64dc6f6810
2 changed files with 24 additions and 0 deletions
6
viper.go
6
viper.go
|
@ -551,6 +551,12 @@ func (v *Viper) GetInt(key string) int {
|
||||||
return cast.ToInt(v.Get(key))
|
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
|
// Returns the value associated with the key as a float64
|
||||||
func GetFloat64(key string) float64 { return v.GetFloat64(key) }
|
func GetFloat64(key string) float64 { return v.GetFloat64(key) }
|
||||||
func (v *Viper) GetFloat64(key string) float64 {
|
func (v *Viper) GetFloat64(key string) float64 {
|
||||||
|
|
|
@ -763,6 +763,7 @@ func TestSub(t *testing.T) {
|
||||||
var yamlMergeExampleTgt = []byte(`
|
var yamlMergeExampleTgt = []byte(`
|
||||||
hello:
|
hello:
|
||||||
pop: 37890
|
pop: 37890
|
||||||
|
lagrenum: 765432101234567
|
||||||
world:
|
world:
|
||||||
- us
|
- us
|
||||||
- uk
|
- uk
|
||||||
|
@ -773,6 +774,7 @@ hello:
|
||||||
var yamlMergeExampleSrc = []byte(`
|
var yamlMergeExampleSrc = []byte(`
|
||||||
hello:
|
hello:
|
||||||
pop: 45000
|
pop: 45000
|
||||||
|
lagrenum: 7654321001234567
|
||||||
universe:
|
universe:
|
||||||
- mw
|
- mw
|
||||||
- ad
|
- ad
|
||||||
|
@ -790,6 +792,14 @@ func TestMergeConfig(t *testing.T) {
|
||||||
t.Fatalf("pop != 37890, = %d", pop)
|
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 {
|
if world := v.GetStringSlice("hello.world"); len(world) != 4 {
|
||||||
t.Fatalf("len(world) != 4, = %d", len(world))
|
t.Fatalf("len(world) != 4, = %d", len(world))
|
||||||
}
|
}
|
||||||
|
@ -806,6 +816,14 @@ func TestMergeConfig(t *testing.T) {
|
||||||
t.Fatalf("pop != 45000, = %d", pop)
|
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 {
|
if world := v.GetStringSlice("hello.world"); len(world) != 4 {
|
||||||
t.Fatalf("len(world) != 4, = %d", len(world))
|
t.Fatalf("len(world) != 4, = %d", len(world))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue