Deep copy maps.
(dst, src map[string]any)
| 833 | |
| 834 | // Deep copy maps. |
| 835 | func mergeMaps(dst, src map[string]any) (map[string]any, bool) { |
| 836 | var changed bool |
| 837 | |
| 838 | if len(src) == 0 { |
| 839 | return dst, changed |
| 840 | } |
| 841 | |
| 842 | if dst == nil { |
| 843 | dst = make(map[string]any) |
| 844 | } |
| 845 | |
| 846 | for key, val := range src { |
| 847 | xval := reflect.ValueOf(val) |
| 848 | switch xval.Kind() { |
| 849 | case reflect.Map: |
| 850 | if xsrc, _ := val.(map[string]any); xsrc != nil { |
| 851 | // Deep-copy map[string]any |
| 852 | xdst, _ := dst[key].(map[string]any) |
| 853 | var lchange bool |
| 854 | dst[key], lchange = mergeMaps(xdst, xsrc) |
| 855 | changed = changed || lchange |
| 856 | } else if val != nil { |
| 857 | // The map is shallow-copied if it's not of the type map[string]any |
| 858 | dst[key] = val |
| 859 | changed = true |
| 860 | } |
| 861 | case reflect.String: |
| 862 | changed = true |
| 863 | if xval.String() == nullValue { |
| 864 | delete(dst, key) |
| 865 | } else if val != nil { |
| 866 | dst[key] = val |
| 867 | } |
| 868 | default: |
| 869 | if val != nil { |
| 870 | dst[key] = val |
| 871 | changed = true |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return dst, changed |
| 877 | } |
| 878 | |
| 879 | // Shallow copy of a map |
| 880 | func copyMap(src map[string]any) map[string]any { |
searching dependent graphs…