MCPcopy Create free account
hub / github.com/caarlos0/env / ExampleParse_separator

Function ExampleParse_separator

example_test.go:107–118  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

105// be used to separate a key from a value in a map.
106// The defaults are `,` and `:`, respectively.
107func 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

Callers

nothing calls this directly

Calls 1

ParseFunction · 0.85

Tested by

no test coverage detected