env icon indicating copy to clipboard operation
env copied to clipboard

support complex map types, where the map value can be a struct

Open SkArchon opened this issue 7 months ago • 0 comments

The proposal is to support complex map types so that we could do the following

type Test struct {
	Str string `env:"DAT_STR"`
	Num int    `env:"DAT_NUM"`
}
type ComplexConfig struct {
	Bar map[string]Test `envPrefix:"BAR_"`
}

t.Setenv("BAR_KEY1_DAT_STR", "b1t")
t.Setenv("BAR_KEY1_DAT_NUM", "201")

This is similar to https://github.com/caarlos0/env/issues/298 but for maps

The key can be any supported value (that are already present in either opts.FuncMap or the default parser list in defaultBuiltInParsers).

I will open a PR for this Issue.

SkArchon avatar May 29 '25 20:05 SkArchon