mirror of
https://github.com/spf13/viper
synced 2024-09-28 18:36:19 +00:00
fix: typo
This commit is contained in:
parent
ea35b92596
commit
591241a57f
|
@ -718,9 +718,9 @@ The resulting code is easy to test, since it's decoupled from the main config st
|
||||||
and easier to reuse (for the same reason).
|
and easier to reuse (for the same reason).
|
||||||
|
|
||||||
|
|
||||||
### Unmarshaling
|
### Unmarshalling
|
||||||
|
|
||||||
You also have the option of Unmarshaling all or a specific value to a struct, map,
|
You also have the option of Unmarshalling all or a specific value to a struct, map,
|
||||||
etc.
|
etc.
|
||||||
|
|
||||||
There are two methods to do this:
|
There are two methods to do this:
|
||||||
|
@ -771,7 +771,7 @@ var C config
|
||||||
v.Unmarshal(&C)
|
v.Unmarshal(&C)
|
||||||
```
|
```
|
||||||
|
|
||||||
Viper also supports unmarshaling into embedded structs:
|
Viper also supports unmarshalling into embedded structs:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
/*
|
/*
|
||||||
|
@ -802,7 +802,7 @@ if err != nil {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshaling values which uses `mapstructure` tags by default.
|
Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshalling values which uses `mapstructure` tags by default.
|
||||||
|
|
||||||
### Decoding custom formats
|
### Decoding custom formats
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Troubleshooting
|
# Troubleshooting
|
||||||
|
|
||||||
## Unmarshaling doesn't work
|
## Unmarshalling doesn't work
|
||||||
|
|
||||||
The most common reason for this issue is improper use of struct tags (eg. `yaml` or `json`). Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshaling values which uses `mapstructure` tags by default. Please refer to the library's documentation for using other struct tags.
|
The most common reason for this issue is improper use of struct tags (eg. `yaml` or `json`). Viper uses [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) under the hood for unmarshalling values which uses `mapstructure` tags by default. Please refer to the library's documentation for using other struct tags.
|
||||||
|
|
||||||
## Cannot find package
|
## Cannot find package
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *vi
|
||||||
}
|
}
|
||||||
quit := make(chan bool)
|
quit := make(chan bool)
|
||||||
quitwc := make(chan bool)
|
quitwc := make(chan bool)
|
||||||
viperResponsCh := make(chan *viper.RemoteResponse)
|
viperResponseCh := make(chan *viper.RemoteResponse)
|
||||||
cryptoResponseCh := cm.Watch(rp.Path(), quit)
|
cryptoResponseCh := cm.Watch(rp.Path(), quit)
|
||||||
// need this function to convert the Channel response form crypt.Response to viper.Response
|
// need this function to convert the Channel response form crypt.Response to viper.Response
|
||||||
go func(cr <-chan *crypt.Response, vr chan<- *viper.RemoteResponse, quitwc <-chan bool, quit chan<- bool) {
|
go func(cr <-chan *crypt.Response, vr chan<- *viper.RemoteResponse, quitwc <-chan bool, quit chan<- bool) {
|
||||||
|
@ -67,9 +67,9 @@ func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *vi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(cryptoResponseCh, viperResponsCh, quitwc, quit)
|
}(cryptoResponseCh, viperResponseCh, quitwc, quit)
|
||||||
|
|
||||||
return viperResponsCh, quitwc
|
return viperResponseCh, quitwc
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
|
func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
|
||||||
|
|
|
@ -432,7 +432,7 @@ func TestDefault(t *testing.T) {
|
||||||
assert.Equal(t, "leather", v.Get("clothing.jacket"))
|
assert.Equal(t, "leather", v.Get("clothing.jacket"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshaling(t *testing.T) {
|
func TestUnmarshalling(t *testing.T) {
|
||||||
v := New()
|
v := New()
|
||||||
v.SetConfigType("yaml")
|
v.SetConfigType("yaml")
|
||||||
r := bytes.NewReader(yamlExample)
|
r := bytes.NewReader(yamlExample)
|
||||||
|
@ -2191,7 +2191,7 @@ func TestMergeConfigMap(t *testing.T) {
|
||||||
assertFn(1234)
|
assertFn(1234)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalingWithAliases(t *testing.T) {
|
func TestUnmarshallingWithAliases(t *testing.T) {
|
||||||
v := New()
|
v := New()
|
||||||
v.SetDefault("ID", 1)
|
v.SetDefault("ID", 1)
|
||||||
v.Set("name", "Steve")
|
v.Set("name", "Steve")
|
||||||
|
|
Loading…
Reference in a new issue