forked from mirror/viper
Add GetInt64
This commit is contained in:
parent
6d2589cd85
commit
64dc6f6810
6
viper.go
6
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 {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue