MCPcopy Create free account
hub / github.com/brettlangdon/forge / Merge

Method Merge

section.go:319–353  ·  view source on GitHub ↗

Merge merges the given section to current section. Settings from source section overwites the values in the current section

(source *Section)

Source from the content-addressed store, hash-verified

317// Merge merges the given section to current section. Settings from source
318// section overwites the values in the current section
319func (section *Section) Merge(source *Section) error {
320 for _, key := range source.Keys() {
321 sourceValue, _ := source.Get(key)
322 targetValue, err := section.Get(key)
323
324 // not found, so add it
325 if err != nil {
326 section.Set(key, sourceValue)
327 continue
328 }
329
330 // found existing one and it's type SECTION, merge it
331 if targetValue.GetType() == SECTION {
332 // Source value have to be SECTION type here
333 if sourceValue.GetType() != SECTION {
334 return fmt.Errorf("source (%v) and target (%v) type doesn't match: %v",
335 sourceValue.GetType(),
336 targetValue.GetType(),
337 key)
338 }
339
340 if err = targetValue.(*Section).Merge(sourceValue.(*Section)); err != nil {
341 return err
342 }
343
344 continue
345 }
346
347 // found existing one, update it
348 if err = targetValue.UpdateValue(sourceValue.GetValue()); err != nil {
349 return fmt.Errorf("%v: %v", err, key)
350 }
351 }
352 return nil
353}
354
355// ToJSON will convert this Section and all it's underlying values and Sections
356// into JSON as a []byte

Callers 2

TestMergeSectionFunction · 0.80

Calls 6

GetMethod · 0.95
SetMethod · 0.95
KeysMethod · 0.80
GetTypeMethod · 0.65
UpdateValueMethod · 0.65
GetValueMethod · 0.65

Tested by 2

TestMergeSectionFunction · 0.64