From 8a592221c5d2c90b1895641e49d56cd437334f09 Mon Sep 17 00:00:00 2001 From: Calin Martinconi Date: Tue, 30 Jul 2024 22:53:22 +0300 Subject: [PATCH 1/2] feat: return uint8 also --- viper.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/viper.go b/viper.go index 754eb5aac..f900e58b1 100644 --- a/viper.go +++ b/viper.go @@ -816,6 +816,13 @@ func (v *Viper) GetInt64(key string) int64 { return cast.ToInt64(v.Get(key)) } +// GetUint8 returns the value associated with the key as an unsigned integer. +func GetUint8(key string) uint8 { return v.GetUint8(key) } + +func (v *Viper) GetUint8(key string) uint8 { + return cast.ToUint8(v.Get(key)) +} + // GetUint returns the value associated with the key as an unsigned integer. func GetUint(key string) uint { return v.GetUint(key) } From dace0febb90d24e4abfff70a0df86bdb842cae78 Mon Sep 17 00:00:00 2001 From: Calin Martinconi Date: Tue, 30 Jul 2024 23:02:00 +0300 Subject: [PATCH 2/2] feat: uint8 test --- viper_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/viper_test.go b/viper_test.go index 2eab0eae4..6c0ce455d 100644 --- a/viper_test.go +++ b/viper_test.go @@ -2039,6 +2039,7 @@ func TestMergeConfig(t *testing.T) { assert.Equal(t, 37890, v.GetInt("hello.pop")) assert.Equal(t, int32(37890), v.GetInt32("hello.pop")) assert.Equal(t, int64(765432101234567), v.GetInt64("hello.largenum")) + assert.Equal(t, uint8(2), v.GetUint8("hello.pop")) assert.Equal(t, uint(37890), v.GetUint("hello.pop")) assert.Equal(t, uint16(37890), v.GetUint16("hello.pop")) assert.Equal(t, uint32(37890), v.GetUint32("hello.pop"))