Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Jan 11, 2024
1 parent 6ada0dc commit 7943c42
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions xload/providers/viper/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,55 @@ func ExampleNew() {
// Output:
// debug
}

func ExampleFrom() {
_, err := viper.New(viper.From(vpr.New()))
if err != nil {
panic(err)
}
}

func ExampleLoader_ConfigFileUsed() {
_, err := viper.New(viper.ConfigFile("<path-to-config-file>.ext"))
if err != nil {
panic(err)
}

fmt.Println(vpr.ConfigFileUsed()) // <path-to-config-file>.ext
}

func ExampleNew_fileOptions() {
_, err := viper.New(
viper.ConfigName("config"),
viper.ConfigType("toml"),
viper.ConfigPaths([]string{"./", "/etc/<program/"}),
)
if err != nil {
panic(err)
}
}

func ExampleAutoEnv_disable() {
_, err := viper.New(viper.AutoEnv(false))
if err != nil {
panic(err)
}
}

func ExampleValueMapper() {
_, err := viper.New(viper.ValueMapper(func(m map[string]any) map[string]string {
return xload.FlattenMap(m, "__")
}))
if err != nil {
panic(err)
}
}

func ExampleTransformer() {
_, err := viper.New(viper.Transformer(func(v *vpr.Viper, next xload.Loader) xload.Loader {
return xload.PrefixLoader("ENV_", next)
}))
if err != nil {
panic(err)
}
}

0 comments on commit 7943c42

Please sign in to comment.