mirror of
https://github.com/spf13/viper
synced 2025-05-07 12:47:18 +00:00
Merge 7ba32f6a08
into d104d259b3
This commit is contained in:
commit
88bae4eb55
3 changed files with 20 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -27,3 +27,4 @@ _testmain.go
|
|||
|
||||
# exclude dependencies in the `/vendor` folder
|
||||
vendor
|
||||
.idea
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/spf13/viper
|
||||
module github.com/pupizoid/viper
|
||||
|
||||
require (
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
|
||||
|
|
24
viper.go
24
viper.go
|
@ -33,19 +33,19 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/hashicorp/hcl"
|
||||
"github.com/hashicorp/hcl/hcl/printer"
|
||||
"github.com/magiconair/properties"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
toml "github.com/pelletier/go-toml"
|
||||
"github.com/nwingert/fsnotify"
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cast"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
)
|
||||
|
||||
// ConfigMarshalError happens when failing to marshal the configuration.
|
||||
type ConfigMarshalError struct {
|
||||
|
@ -203,6 +203,8 @@ type Viper struct {
|
|||
properties *properties.Properties
|
||||
|
||||
onConfigChange func(fsnotify.Event)
|
||||
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
// New returns an initialized Viper instance.
|
||||
|
@ -952,6 +954,8 @@ func (v *Viper) BindEnv(input ...string) error {
|
|||
// Viper will check to see if an alias exists first.
|
||||
// Note: this assumes a lower-cased key given.
|
||||
func (v *Viper) find(lcaseKey string) interface{} {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
|
||||
var (
|
||||
val interface{}
|
||||
|
@ -1222,8 +1226,9 @@ func (v *Viper) ReadInConfig() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v.Lock()
|
||||
v.config = config
|
||||
v.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1655,6 +1660,9 @@ func (v *Viper) watchRemoteConfig(provider RemoteProvider) (map[string]interface
|
|||
// Nested keys are returned with a v.keyDelim (= ".") separator
|
||||
func AllKeys() []string { return v.AllKeys() }
|
||||
func (v *Viper) AllKeys() []string {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
|
||||
m := map[string]bool{}
|
||||
// add all paths, by order of descending priority to ensure correct shadowing
|
||||
m = v.flattenAndMergeMap(m, castMapStringToMapInterface(v.aliases), "")
|
||||
|
@ -1664,7 +1672,6 @@ func (v *Viper) AllKeys() []string {
|
|||
m = v.flattenAndMergeMap(m, v.config, "")
|
||||
m = v.flattenAndMergeMap(m, v.kvstore, "")
|
||||
m = v.flattenAndMergeMap(m, v.defaults, "")
|
||||
|
||||
// convert set of paths to list
|
||||
a := []string{}
|
||||
for x := range m {
|
||||
|
@ -1739,6 +1746,11 @@ func (v *Viper) AllSettings() map[string]interface{} {
|
|||
// start from the list of keys, and construct the map one value at a time
|
||||
for _, k := range v.AllKeys() {
|
||||
value := v.Get(k)
|
||||
// ensure that marshalling to json will be supported
|
||||
switch v := value.(type) {
|
||||
case map[interface{}]interface{}:
|
||||
value = castToMapStringInterface(v)
|
||||
}
|
||||
if value == nil {
|
||||
// should not happen, since AllKeys() returns only keys holding a value,
|
||||
// check just in case anything changes
|
||||
|
|
Loading…
Add table
Reference in a new issue