add GetUint/GetUint32/GetUint64

This commit is contained in:
smoreg 2018-06-21 22:27:44 +03:00 committed by Kirill Semenchenko
parent 15738813a0
commit 7e20eda4ff
2 changed files with 31 additions and 0 deletions

View file

@ -694,6 +694,24 @@ func (v *Viper) GetInt64(key string) int64 {
return cast.ToInt64(v.Get(key)) return cast.ToInt64(v.Get(key))
} }
// GetUint returns the value associated with the key as an unsigned integer.
func GetUint(key string) uint { return v.GetUint(key) }
func (v *Viper) GetUint(key string) uint {
return cast.ToUint(v.Get(key))
}
// GetUint32 returns the value associated with the key as an unsigned integer.
func GetUint32(key string) uint32 { return v.GetUint32(key) }
func (v *Viper) GetUint32(key string) uint32 {
return cast.ToUint32(v.Get(key))
}
// GetUint64 returns the value associated with the key as an unsigned integer.
func GetUint64(key string) uint64 { return v.GetUint64(key) }
func (v *Viper) GetUint64(key string) uint64 {
return cast.ToUint64(v.Get(key))
}
// GetFloat64 returns the value associated with the key as a float64. // GetFloat64 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 {

View file

@ -1036,6 +1036,7 @@ var yamlMergeExampleTgt = []byte(`
hello: hello:
pop: 37890 pop: 37890
lagrenum: 765432101234567 lagrenum: 765432101234567
num2pow63: 9223372036854775808
world: world:
- us - us
- uk - uk
@ -1076,6 +1077,18 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("int64 lagrenum != 765432101234567, = %d", pop) t.Fatalf("int64 lagrenum != 765432101234567, = %d", pop)
} }
if pop := v.GetUint("hello.pop"); pop != 37890 {
t.Fatalf("uint pop != 37890, = %d", pop)
}
if pop := v.GetUint32("hello.pop"); pop != 37890 {
t.Fatalf("uint32 pop != 37890, = %d", pop)
}
if pop := v.GetUint64("hello.num2pow63"); pop != 9223372036854775808 {
t.Fatalf("uint64 num2pow63 != 9223372036854775808, = %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))
} }