Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for uint16 with GetUint16 #1405

Merged
merged 1 commit into from Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions viper.go
Expand Up @@ -991,6 +991,13 @@ func (v *Viper) GetUint(key string) uint {
return cast.ToUint(v.Get(key))
}

// GetUint16 returns the value associated with the key as an unsigned integer.
func GetUint16(key string) uint16 { return v.GetUint16(key) }

func (v *Viper) GetUint16(key string) uint16 {
return cast.ToUint16(v.Get(key))
}

// GetUint32 returns the value associated with the key as an unsigned integer.
func GetUint32(key string) uint32 { return v.GetUint32(key) }

Expand Down
4 changes: 4 additions & 0 deletions viper_test.go
Expand Up @@ -1953,6 +1953,10 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("uint pop != 37890, = %d", pop)
}

if pop := v.GetUint16("hello.pop"); pop != uint16(37890) {
t.Fatalf("uint pop != 37890, = %d", pop)
}

if pop := v.GetUint32("hello.pop"); pop != 37890 {
t.Fatalf("uint32 pop != 37890, = %d", pop)
}
Expand Down