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

Smaller integers cannot be marshalled into #70

Open
stevefan1999-personal opened this issue Jun 11, 2022 · 1 comment
Open

Smaller integers cannot be marshalled into #70

stevefan1999-personal opened this issue Jun 11, 2022 · 1 comment

Comments

@stevefan1999-personal
Copy link

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
@stevefan1999-personal
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant