mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
add GetUint/GetUint32/GetUint64
This commit is contained in:
parent
15738813a0
commit
7e20eda4ff
2 changed files with 31 additions and 0 deletions
18
viper.go
18
viper.go
|
@ -694,6 +694,24 @@ func (v *Viper) GetInt64(key string) int64 {
|
|||
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.
|
||||
func GetFloat64(key string) float64 { return v.GetFloat64(key) }
|
||||
func (v *Viper) GetFloat64(key string) float64 {
|
||||
|
|
|
@ -1036,6 +1036,7 @@ var yamlMergeExampleTgt = []byte(`
|
|||
hello:
|
||||
pop: 37890
|
||||
lagrenum: 765432101234567
|
||||
num2pow63: 9223372036854775808
|
||||
world:
|
||||
- us
|
||||
- uk
|
||||
|
@ -1076,6 +1077,18 @@ func TestMergeConfig(t *testing.T) {
|
|||
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 {
|
||||
t.Fatalf("len(world) != 4, = %d", len(world))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue