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

Case sensitive problems #185

Closed
ghpu opened this issue Dec 16, 2022 · 1 comment
Closed

Case sensitive problems #185

ghpu opened this issue Dec 16, 2022 · 1 comment

Comments

@ghpu
Copy link

ghpu commented Dec 16, 2022

Koanf version 1.4.4

I have a yaml conf like this :

env:
   name: toto

which I load with :

type MyStruct struct {
Name string `koanf:"name"`
}

var env MyStruct
k:= koanf.New(".")
k.Load(file.Provider("conf.yaml"), parser)
k.Unmarshal("env", &env)

If I change "name" to "Name", the value "toto" is still parsed into env.Name !

However, if i register default values first

k.Load(confmap.Provider(map[string]interface{}{
"env.name": nil
},"."), nil)

Then the case sensitive is working as expected, and env.Name remains empty .

@knadh
Copy link
Owner

knadh commented Dec 17, 2022

All keys are case-sensitive inside koanf's confmap, but the mapstructure lib that it uses to unmarshal the keys into struct does ~fuzzy matching of names on struct field tags. To enforce, case sensitivity there, you can pass a matcher function to mapstructure's DecoderConfig.

eg:

ko.UnmarshalWithConf("key", &o, koanf.UnmarshalConf{DecoderConfig: &mapstructure.DecoderConfig{...}})

See: mitchellh/mapstructure#250

@knadh knadh closed this as completed Dec 17, 2022
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

2 participants