()
| 23 | } |
| 24 | |
| 25 | func 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 | } |
nothing calls this directly
no test coverage detected