MCPcopy
hub / github.com/spf13/viper / overrideFromLayer

Function overrideFromLayer

overrides_test.go:96–126  ·  view source on GitHub ↗

overrideFromLayer performs the sequential override and low-level checks. First assignment is made on layer l for path firstPath with value firstValue, the second one on the override layer (i.e., with the Set() function) for path secondPath with value secondValue. firstPath and secondPath can inclu

(l layer, assert *assert.Assertions, firstPath string, firstValue any, secondPath string, secondValue any)

Source from the content-addressed store, hash-verified

94// After each assignment, the value is checked, retrieved both by its full path
95// and by its key sequence (successive maps).
96func overrideFromLayer(l layer, assert *assert.Assertions, firstPath string, firstValue any, secondPath string, secondValue any) *Viper {
97 v := New()
98 firstKeys := strings.Split(firstPath, v.keyDelim)
99 if assert == nil ||
100 len(firstKeys) == 0 || firstKeys[0] == "" {
101 return v
102 }
103
104 // Set and check first value
105 switch l {
106 case defaultLayer:
107 v.SetDefault(firstPath, firstValue)
108 case overrideLayer:
109 v.Set(firstPath, firstValue)
110 default:
111 return v
112 }
113 assert.Equal(firstValue, v.Get(firstPath))
114 deepCheckValue(assert, v, l, firstKeys, firstValue)
115
116 // Override and check new value
117 secondKeys := strings.Split(secondPath, v.keyDelim)
118 if len(secondKeys) == 0 || secondKeys[0] == "" {
119 return v
120 }
121 v.Set(secondPath, secondValue)
122 assert.Equal(secondValue, v.Get(secondPath))
123 deepCheckValue(assert, v, overrideLayer, secondKeys, secondValue)
124
125 return v
126}
127
128// deepCheckValue checks that all given keys correspond to a valid path in the
129// configuration map of the given layer, and that the final value equals the one given.

Callers 2

overrideDefaultFunction · 0.85
overrideFunction · 0.85

Calls 5

NewFunction · 0.85
deepCheckValueFunction · 0.85
SetDefaultMethod · 0.80
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected