ilyakaznacheev / cleanenv

✨Clean and minimalistic environment configuration reader for Golang
MIT License
1.61k stars 111 forks source link

Does this support parsing `map[string]CustomStruct` using the `env` tag? #108

Open jasonlimantoro opened 1 year ago

jasonlimantoro commented 1 year ago

For example, I have the following Config root


var RootConfig Root

type Root struct {
    Http map[string]HttpConfig `yaml:"http" env:"HTTP"`
}

type HttpConfig struct {
    Host      string `yaml:"host"`
    TimeoutMs int    `yaml:"timeout_ms"`
}

func Load(configPath string) {
    cleanenv.ReadConfig(configPath, &RootConfig)
}

I know I can provide the following to populate http key via the following yaml structure:

http:
  payment:
    host: "http://payment:4000"
    timeout_ms: 2000

But what about via environment variable? What would HTTP env var look like?

eloo commented 1 year ago

i'm also interested here as i have a similar usecase :)

would be really great if this would be possible

Larleyt commented 3 months ago

Bumping this issue, have a problem with a map, too.