You can use `envSeparator` to define which character should be used to separate array items in a string. Similarly, you can use `envKeyValSeparator` to define which character should be used to separate a key from a value in a map. The defaults are `,` and `:`, respectively.
()
| 105 | // be used to separate a key from a value in a map. |
| 106 | // The defaults are `,` and `:`, respectively. |
| 107 | func ExampleParse_separator() { |
| 108 | type Config struct { |
| 109 | Map map[string]string `env:"CUSTOM_MAP" envSeparator:"-" envKeyValSeparator:"|"` |
| 110 | } |
| 111 | os.Setenv("CUSTOM_MAP", "k1|v1-k2|v2") |
| 112 | var cfg Config |
| 113 | if err := Parse(&cfg); err != nil { |
| 114 | fmt.Println(err) |
| 115 | } |
| 116 | fmt.Printf("%+v", cfg) |
| 117 | // Output: {Map:map[k1:v1 k2:v2]} |
| 118 | } |
| 119 | |
| 120 | // If you set the `expand` option, environment variables (either in `${var}` or |
| 121 | // `$var` format) in the string will be replaced according with the actual |