lalamove / konfig

Composable, observable and performant config handling for Go for the distributed processing era

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Smaller integers cannot be marshalled into

stevefan1999-personal opened this issue · comments

Here's an example

type Config struct {
	Port    uint16
}

config.yml:

port: 8080
FILEWATCHER | 2022/06/11 19:46:20 adding file to watch: ./config.yml
panic: reflect.Set: value of type int is not assignable to type uint16

goroutine 1 [running]:
reflect.Value.assignTo({0x111ce80?, 0x13a84e0?, 0xc0001a4300?}, {0x1177edc, 0xb}, 0x111d7c0, 0x0)
        C:/Program Files/Go/src/reflect/value.go:3062 +0x2ac
reflect.Value.Set({0x111d7c0?, 0xc0001a4300?, 0x111ce80?}, {0x111ce80?, 0x13a84e0?, 0x111d7c0?})
        C:/Program Files/Go/src/reflect/value.go:2088 +0xeb
github.com/lalamove/konfig.(*value).setStruct(0xc00019a3f0, {0xc0001a2600, 0x4}, {0x111ce80, 0x13a84e0}, {0x1113e20?, 0xc0001a4300?, 0x30000?})
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/value.go:221 +0x34f
github.com/lalamove/konfig.(*value).setValues(0xc00019a3f0, 0xc00019a8a0?)
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/value.go:196 +0x22f
github.com/lalamove/konfig.Values.load(0xc00019a510, 0x111b440?, 0xc00019c0b0)
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/values.go:61 +0x738
github.com/lalamove/konfig.(*S).loaderLoadRetry(0xc00019c0b0, 0xc000180060, 0x0)
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/loader.go:149 +0x276
github.com/lalamove/konfig.(*S).Load(0xc00019c0b0)
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/loader.go:69 +0x74
github.com/lalamove/konfig.(*S).LoadWatch(0x1?)
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/loader.go:49 +0x1e
github.com/lalamove/konfig.LoadWatch()
        C:/Users/steve/go/pkg/mod/github.com/lalamove/konfig@v0.8.3/loader.go:44 +0x1e

Seems like uint16 is deliberately elided out

konfig/value.go

Lines 372 to 375 in 5b61527

case uint32:
return cast.ToUint32(v)
case uint8:
return cast.ToUint8(v)