Parse the environment into a struct using generics.
()
| 42 | |
| 43 | // Parse the environment into a struct using generics. |
| 44 | func ExampleParseAs() { |
| 45 | type Config struct { |
| 46 | Home string `env:"HOME"` |
| 47 | } |
| 48 | os.Setenv("HOME", "/tmp/fakehome") |
| 49 | cfg, err := ParseAs[Config]() |
| 50 | if err != nil { |
| 51 | fmt.Println(err) |
| 52 | } |
| 53 | fmt.Printf("%+v", cfg) |
| 54 | // Output: {Home:/tmp/fakehome} |
| 55 | } |
| 56 | |
| 57 | func ExampleParse_required() { |
| 58 | type Config struct { |
nothing calls this directly
no outgoing calls
no test coverage detected