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

Example of using map of structs in config, example of using env-separator #143

Open
Larleyt opened this issue Jun 14, 2024 · 0 comments
Open

Comments

@Larleyt
Copy link

Larleyt commented Jun 14, 2024

The docs say:
env-separator="<value>" - custom list and map separator. If not set, the default separator , will be used;
implying maps with arbitrary keys are supported. Yet, there's no example for it.

It is unclear how to assign env variable to a attribute of a struct which is a value of a map:

Let's say we have:
config.go:

Animals map[string]Animal  `yaml:"animals" env:"ANIMALS"`

Animal struct {
   Name: string `yaml:"name" env:"NAME"`
}

config.yaml:

animals: 
    dog:
        name: "Rocky"
    cat: 
        name: "Jack"
  1. How do I provide names through env vars?
    Is it ANIMALS_DOG_NAME/ANIMALS_CAT_NAME or what?

  2. What's env-separator is about?

@ilyakaznacheev

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

1 participant