()
| 10 | ) |
| 11 | |
| 12 | func 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 | |
| 40 | func ExampleFinders() { |
| 41 | fs := afero.NewMemMapFs() |
nothing calls this directly
no test coverage detected