/koanfenv

koanfenv provides koanf callbacks that translate environment variables to koanf keys.

Primary LanguageGoMIT LicenseMIT

koanfenv

CI CircleCI codecov Go Reference

koanfenv provides callbacks which convert environment variables to koanf keys. These callbacks are used for env.Provider .

Usage

config := struct{
	Foo1 string `koanf:"foo1" env:"APP_FOO1"`
}{}

k := koanf.New(".")
if err := k.Load(env.Provider("APP_", ".", koanfenv.ByStruct(&config)), nil); err != nil {
	log.Fatal(err)
}
m := map[string]string{
	"APP_FOO1": "foo1",
}

k := koanf.New(".")
if err := k.Load(env.Provider("APP_", ".", koanfenv.ByMap(m)), nil); err != nil {
	log.Fatal(err)
}

License

MIT