MCPcopy
hub / github.com/tinode/chat / mergeInterfaces

Function mergeInterfaces

server/utils.go:802–832  ·  view source on GitHub ↗

Merge source interface{} into destination interface. If values are maps,deep-merge them. Otherwise shallow-copy. Returns dst, true if the dst value was changed.

(dst, src any)

Source from the content-addressed store, hash-verified

800// If values are maps,deep-merge them. Otherwise shallow-copy.
801// Returns dst, true if the dst value was changed.
802func mergeInterfaces(dst, src any) (any, bool) {
803 var changed bool
804
805 if src == nil {
806 return dst, changed
807 }
808
809 vsrc := reflect.ValueOf(src)
810 switch vsrc.Kind() {
811 case reflect.Map:
812 if xsrc, ok := src.(map[string]any); ok {
813 xdst, _ := dst.(map[string]any)
814 dst, changed = mergeMaps(xdst, xsrc)
815 } else {
816 changed = true
817 dst = src
818 }
819 case reflect.String:
820 if vsrc.String() == nullValue {
821 changed = dst != nil
822 dst = nil
823 } else {
824 changed = true
825 dst = src
826 }
827 default:
828 changed = true
829 dst = src
830 }
831 return dst, changed
832}
833
834// Deep copy maps.
835func mergeMaps(dst, src map[string]any) (map[string]any, bool) {

Callers 3

TestMergeInterfacesFunction · 0.85
replyOfflineTopicSetSubFunction · 0.85
replySetDescMethod · 0.85

Calls 2

mergeMapsFunction · 0.85
StringMethod · 0.45

Tested by 1

TestMergeInterfacesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…