Make all fields required by default.
()
| 258 | |
| 259 | // Make all fields required by default. |
| 260 | func ExampleParseWithOptions_allFieldsRequired() { |
| 261 | type Config struct { |
| 262 | Username string `env:"EX_USERNAME" envDefault:"admin"` |
| 263 | Password string `env:"EX_PASSWORD"` |
| 264 | } |
| 265 | |
| 266 | var cfg Config |
| 267 | if err := ParseWithOptions(&cfg, Options{ |
| 268 | RequiredIfNoDef: true, |
| 269 | }); err != nil { |
| 270 | fmt.Println(err) |
| 271 | } |
| 272 | fmt.Printf("%+v\n", cfg) |
| 273 | // Output: env: required environment variable "EX_PASSWORD" is not set |
| 274 | // {Username:admin Password:} |
| 275 | } |
| 276 | |
| 277 | // Set a custom environment. |
| 278 | // By default, `os.Environ()` is used. |
nothing calls this directly
no test coverage detected