MCPcopy Index your code
hub / github.com/devspace-sh/devspace / applyMerge

Function applyMerge

pkg/devspace/config/loader/profile.go:106–147  ·  view source on GitHub ↗
(config map[string]interface{}, key string, value interface{})

Source from the content-addressed store, hash-verified

104}
105
106func applyMerge(config map[string]interface{}, key string, value interface{}) (map[string]interface{}, error) {
107 if value == nil {
108 return config, nil
109 }
110 switch t := value.(type) {
111 case []interface{}:
112 if t == nil {
113 return config, nil
114 }
115 case map[string]interface{}:
116 if t == nil {
117 return config, nil
118 }
119 }
120
121 mergeObj := map[string]interface{}{
122 key: value,
123 }
124
125 mergeBytes, err := json.Marshal(mergeObj)
126 if err != nil {
127 return nil, errors.Wrap(err, "marshal merge")
128 }
129
130 originalBytes, err := json.Marshal(config)
131 if err != nil {
132 return nil, errors.Wrap(err, "marshal merge")
133 }
134
135 out, err := jsonpatch.MergePatch(originalBytes, mergeBytes)
136 if err != nil {
137 return nil, errors.Wrap(err, "create merge patch")
138 }
139
140 strMap := map[string]interface{}{}
141 err = json.Unmarshal(out, &strMap)
142 if err != nil {
143 return nil, err
144 }
145
146 return strMap, nil
147}
148
149// ApplyReplace applies the replaces
150func ApplyReplace(config map[string]interface{}, profile *latest.ProfileConfig) error {

Callers 1

ApplyMergeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected