mirror of
https://github.com/spf13/viper
synced 2025-05-06 04:07:17 +00:00
Add Unset method
Before, we would set entries to nil to unset them
This commit is contained in:
parent
da54697d46
commit
0b35ab4493
1 changed files with 16 additions and 0 deletions
16
viper.go
16
viper.go
|
@ -1269,6 +1269,22 @@ func (v *Viper) Set(key string, value interface{}) {
|
|||
deepestMap[lastKey] = value
|
||||
}
|
||||
|
||||
// Unset removes a value set with Set
|
||||
// Unset is case-insensitive for a key.
|
||||
// Values which come from flags, config file, ENV or default can't be unset.
|
||||
func Unset(key string) { v.Unset(key) }
|
||||
func (v *Viper) Unset(key string) {
|
||||
// If alias passed in, then set the proper override
|
||||
key = v.realKey(strings.ToLower(key))
|
||||
|
||||
path := strings.Split(key, v.keyDelim)
|
||||
lastKey := strings.ToLower(path[len(path)-1])
|
||||
deepestMap := deepSearch(v.override, path[0:len(path)-1])
|
||||
|
||||
// unset innermost value
|
||||
delete(deepestMap, lastKey)
|
||||
}
|
||||
|
||||
// ReadInConfig will discover and load the configuration file from disk
|
||||
// and key/value stores, searching in one of the defined paths.
|
||||
func ReadInConfig() error { return v.ReadInConfig() }
|
||||
|
|
Loading…
Add table
Reference in a new issue