-
Notifications
You must be signed in to change notification settings - Fork 158
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
Env Vars Starting with USER
not loading
#319
Comments
hmm, that can't be. It must have something to do with the environment you're in. Works as expected on Linux. package main
import (
"fmt"
"strings"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/v2"
)
func main() {
k := koanf.New(".")
if err := k.Load(env.Provider("", "", func(s string) string {
return strings.ToLower(s)
}), nil); err != nil {
panic(fmt.Errorf("koanf load: %v", err))
}
s := struct {
ValueHere string `config:"value_here"`
UserValueHere string `config:"user_value_here"`
}{}
err := k.UnmarshalWithConf("", &s, koanf.UnmarshalConf{
Tag: "config",
FlatPaths: true,
})
if err != nil {
panic(err)
}
fmt.Println(s)
} $ VALUE_HERE=val1 USER_VALUE_HERE=val2 go run main.go
{val1 val2} |
Looks like it has something to do with the fact that I also have a |
It's not possible that a certain env var breaks the rest of the vars. All env vars are iterated through and processed individually. |
Apologies for the delayed response here. We just renamed the vars as a workaround for now. I'll work on a better reproduction next week and get back to you @knadh |
If I add the following (to temporarily remove
Also, if I copy-paste your code and run it exactly, I get an empty output 🤔
|
@knadh Can you try your code with |
Ah, that's the culprit! The delim is mandatory in Eg: package main
import (
"fmt"
"strings"
"github.com/knadh/koanf/providers/env"
)
func main() {
p := env.Provider("", "", func(s string) string {
return strings.ToLower(s)
})
fmt.Println(p.Read())
} Prints a massive text dump where every character in every env key is split, ouch. eg: |
🤝 Thanks for the quick PR to resolve @knadh ! When do you think that could make it into a release? |
This is merged. You can do a |
Describe the bug
Env Vars Starting with
USER
not loadingTo Reproduce
Expected behavior
Both env vars are mapped to the input struct
Please provide the following information):
The text was updated successfully, but these errors were encountered: