The `env` tag option `file` (e.g., `env:"tagKey,file"`) can be added in order to indicate that the value of the variable shall be loaded from a file. The path of that file is given by the environment variable associated with it.
()
| 398 | // The path of that file is given by the environment variable associated with |
| 399 | // it. |
| 400 | func ExampleParse_fromFile() { |
| 401 | f, _ := os.CreateTemp("", "") |
| 402 | _, _ = f.WriteString("super secret") |
| 403 | _ = f.Close() |
| 404 | |
| 405 | type Config struct { |
| 406 | Secret string `env:"SECRET,file"` |
| 407 | } |
| 408 | os.Setenv("SECRET", f.Name()) |
| 409 | var cfg Config |
| 410 | if err := Parse(&cfg); err != nil { |
| 411 | fmt.Println(err) |
| 412 | } |
| 413 | fmt.Printf("%+v", cfg) |
| 414 | // Output: {Secret:super secret} |
| 415 | } |
| 416 | |
| 417 | // TODO: envSeperator |
| 418 | // |