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

Function ExampleParse_required

example_test.go:57–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55}
56
57func ExampleParse_required() {
58 type Config struct {
59 Nope string `env:"NOPE,required"`
60 }
61 var cfg Config
62 if err := Parse(&cfg); err != nil {
63 fmt.Println(err)
64 }
65 fmt.Printf("%+v", cfg)
66 // Output: env: required environment variable "NOPE" is not set
67 // {Nope:}
68}
69
70// While `required` demands the environment variable to be set, it doesn't check
71// its value. If you want to make sure the environment is set and not empty, you

Callers

nothing calls this directly

Calls 1

ParseFunction · 0.85

Tested by

no test coverage detected