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

Function Example

example_test.go:11–27  ·  view source on GitHub ↗

Basic package usage example.

()

Source from the content-addressed store, hash-verified

9
10// Basic package usage example.
11func Example() {
12 type Config struct {
13 Foo string `env:"FOO"`
14 }
15
16 os.Setenv("FOO", "bar")
17
18 // parse:
19 var cfg1 Config
20 _ = Parse(&cfg1)
21
22 // parse with generics:
23 cfg2, _ := ParseAs[Config]()
24
25 fmt.Print(cfg1.Foo, cfg2.Foo)
26 // Output: barbar
27}
28
29// Parse the environment into a struct.
30func ExampleParse() {

Callers

nothing calls this directly

Calls 1

ParseFunction · 0.85

Tested by

no test coverage detected