If you don't want to set the `env` tag on every field, you can use the `UseFieldNameByDefault` option. It will use the field name to define the environment variable name. So, `Foo` becomes `FOO`, `FooBar` becomes `FOO_BAR`, and so on.
()
| 377 | // It will use the field name to define the environment variable name. |
| 378 | // So, `Foo` becomes `FOO`, `FooBar` becomes `FOO_BAR`, and so on. |
| 379 | func ExampleParseWithOptions_useFieldName() { |
| 380 | type Config struct { |
| 381 | Foo string |
| 382 | } |
| 383 | os.Setenv("FOO", "bar") |
| 384 | var cfg Config |
| 385 | if err := ParseWithOptions(&cfg, Options{ |
| 386 | UseFieldNameByDefault: true, |
| 387 | }); err != nil { |
| 388 | fmt.Println(err) |
| 389 | } |
| 390 | fmt.Printf("%+v", cfg) |
| 391 | // Output: {Foo:bar} |
| 392 | } |
| 393 | |
| 394 | // The `env` tag option `file` (e.g., `env:"tagKey,file"`) can be added in |
| 395 | // order to indicate that the value of the variable shall be loaded from a |
nothing calls this directly
no test coverage detected