MCPcopy
hub / github.com/spf13/viper / ExampleFinder

Function ExampleFinder

finder_example_test.go:12–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func ExampleFinder() {
13 fs := afero.NewMemMapFs()
14
15 fs.Mkdir("/home/user", 0o777)
16
17 f, _ := fs.Create("/home/user/myapp.yaml")
18 f.WriteString("foo: bar")
19 f.Close()
20
21 // HCL will have a "lower" priority in the search order
22 fs.Create("/home/user/myapp.hcl")
23
24 finder := locafero.Finder{
25 Paths: []string{"/home/user"},
26 Names: locafero.NameWithExtensions("myapp", viper.SupportedExts...),
27 Type: locafero.FileTypeFile, // This is important!
28 }
29
30 v := viper.NewWithOptions(viper.WithFinder(finder))
31 v.SetFs(fs)
32 v.ReadInConfig()
33
34 fmt.Println(v.GetString("foo"))
35
36 // Output:
37 // bar
38}
39
40func ExampleFinders() {
41 fs := afero.NewMemMapFs()

Callers

nothing calls this directly

Calls 5

NewWithOptionsFunction · 0.92
WithFinderFunction · 0.92
SetFsMethod · 0.80
ReadInConfigMethod · 0.80
GetStringMethod · 0.80

Tested by

no test coverage detected