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

Function Example_parseEmptyEnvFallsBackToDefault

example_test.go:485–496  ·  view source on GitHub ↗

An environment variable that is set but empty falls back to envDefault.

()

Source from the content-addressed store, hash-verified

483
484// An environment variable that is set but empty falls back to envDefault.
485func Example_parseEmptyEnvFallsBackToDefault() {
486 type Config struct {
487 Foo string `env:"FOO" envDefault:"fallback"`
488 }
489
490 os.Setenv("FOO", "")
491
492 cfg, _ := ParseAs[Config]()
493
494 fmt.Println(cfg.Foo)
495 // Output: fallback
496}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected