Set a custom environment. By default, `os.Environ()` is used.
()
| 277 | // Set a custom environment. |
| 278 | // By default, `os.Environ()` is used. |
| 279 | func ExampleParseWithOptions_setEnv() { |
| 280 | type Config struct { |
| 281 | Username string `env:"EX_USERNAME" envDefault:"admin"` |
| 282 | Password string `env:"EX_PASSWORD"` |
| 283 | } |
| 284 | |
| 285 | var cfg Config |
| 286 | if err := ParseWithOptions(&cfg, Options{ |
| 287 | Environment: map[string]string{ |
| 288 | "EX_USERNAME": "john", |
| 289 | "EX_PASSWORD": "cena", |
| 290 | }, |
| 291 | }); err != nil { |
| 292 | fmt.Println(err) |
| 293 | } |
| 294 | fmt.Printf("%+v\n", cfg) |
| 295 | // Output: {Username:john Password:cena} |
| 296 | } |
| 297 | |
| 298 | // Handling slices of complex types. |
| 299 | func ExampleParse_complexSlices() { |
nothing calls this directly
no test coverage detected