Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Add SetRawConfig method (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Jul 17, 2019
1 parent 3c5a66b commit 8d638da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,14 @@ func (v *Viper) ReadInConfig() error {
return nil
}

// SetRawConfig overwrites the raw config.
func SetRawConfig(config map[string]interface{}) { v.SetRawConfig(config) }
func (v *Viper) SetRawConfig(config map[string]interface{}) {
v.lock.Lock()
defer v.lock.Unlock()
v.config = config
}

// MergeInConfig merges a new configuration with an existing config.
func MergeInConfig() error { return v.MergeInConfig() }
func (v *Viper) MergeInConfig() error {
Expand Down
6 changes: 6 additions & 0 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,12 @@ bar:
wg.Wait()
}

func TestSetRawConfig(t *testing.T) {
Reset()
SetRawConfig(map[string]interface{}{"foo": "bar"})
assert.Equal(t, "bar", Get("foo"))
}

func BenchmarkGetBool(b *testing.B) {
key := "BenchmarkGetBool"
v = New()
Expand Down

0 comments on commit 8d638da

Please sign in to comment.