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

Function ExampleParseWithOptions_prefix

example_test.go:341–354  ·  view source on GitHub ↗

Setting prefixes for the entire config.

()

Source from the content-addressed store, hash-verified

339
340// Setting prefixes for the entire config.
341func ExampleParseWithOptions_prefix() {
342 type Config struct {
343 Foo string `env:"FOO"`
344 }
345 os.Setenv("MY_APP_FOO", "a")
346 var cfg Config
347 if err := ParseWithOptions(&cfg, Options{
348 Prefix: "MY_APP_",
349 }); err != nil {
350 fmt.Println(err)
351 }
352 fmt.Printf("%+v", cfg)
353 // Output: {Foo:a}
354}
355
356// Use a different tag name than `env` and `envDefault`.
357func ExampleParseWithOptions_tagName() {

Callers

nothing calls this directly

Calls 1

ParseWithOptionsFunction · 0.85

Tested by

no test coverage detected