MCPcopy Create free account
hub / github.com/DoNewsCode/core / Example_configurationStack

Function Example_configurationStack

config/example_test.go:25–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25func Example_configurationStack() {
26 fs := flag.NewFlagSet("config", flag.ContinueOnError)
27 fs.String("foo", "", "foo value")
28 fs.Parse([]string{"-foo", "bar"})
29 conf, _ := config.NewConfig(
30 config.WithProviderLayer(
31 basicflag.Provider(fs, "."), nil,
32 ),
33 config.WithProviderLayer(
34 confmap.Provider(map[string]interface{}{"foo": "baz"}, "."), nil,
35 ),
36 )
37 // We have two layers of configuration, the first one from flags and the second one from a map.
38 // Both of them defined "foo". The first one should take precedence.
39 fmt.Println(conf.String("foo"))
40 // Output:
41 // bar
42}

Callers

nothing calls this directly

Calls 4

NewConfigFunction · 0.92
WithProviderLayerFunction · 0.92
ParseMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected