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

Function ExampleParseAs

example_test.go:44–55  ·  view source on GitHub ↗

Parse the environment into a struct using generics.

()

Source from the content-addressed store, hash-verified

42
43// Parse the environment into a struct using generics.
44func 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
57func ExampleParse_required() {
58 type Config struct {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected