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

Function ExampleParse

example_test.go:30–41  ·  view source on GitHub ↗

Parse the environment into a struct.

()

Source from the content-addressed store, hash-verified

28
29// Parse the environment into a struct.
30func ExampleParse() {
31 type Config struct {
32 Home string `env:"HOME"`
33 }
34 os.Setenv("HOME", "/tmp/fakehome")
35 var cfg Config
36 if err := Parse(&cfg); err != nil {
37 fmt.Println(err)
38 }
39 fmt.Printf("%+v", cfg)
40 // Output: {Home:/tmp/fakehome}
41}
42
43// Parse the environment into a struct using generics.
44func ExampleParseAs() {

Callers

nothing calls this directly

Calls 1

ParseFunction · 0.85

Tested by

no test coverage detected