The `env` tag option `unset` (e.g., `env:"tagKey,unset"`) can be added to ensure that some environment variable is unset after reading it.
()
| 87 | // The `env` tag option `unset` (e.g., `env:"tagKey,unset"`) can be added |
| 88 | // to ensure that some environment variable is unset after reading it. |
| 89 | func ExampleParse_unset() { |
| 90 | type Config struct { |
| 91 | Secret string `env:"SECRET,unset"` |
| 92 | } |
| 93 | os.Setenv("SECRET", "1234") |
| 94 | var cfg Config |
| 95 | if err := Parse(&cfg); err != nil { |
| 96 | fmt.Println(err) |
| 97 | } |
| 98 | fmt.Printf("%+v - %s", cfg, os.Getenv("SECRET")) |
| 99 | // Output: {Secret:1234} - |
| 100 | } |
| 101 | |
| 102 | // You can use `envSeparator` to define which character should be used to |
| 103 | // separate array items in a string. |