func replaceEmptyStructsAndSlicesWithNil()

in operatortrace-go/pkg/predicates/ignore_trace_annotation_update.go [134:164]


func replaceEmptyStructsAndSlicesWithNil(m map[string]interface{}) {
	for k, v := range m {
		switch val := v.(type) {
		case map[string]interface{}:
			if len(val) == 0 {
				m[k] = nil
			} else {
				replaceEmptyStructsAndSlicesWithNil(val)
			}
		case []interface{}:
			if len(val) == 0 {
				m[k] = nil
			} else {
				allElementsEmpty := true
				for _, elem := range val {
					if elemMap, ok := elem.(map[string]interface{}); ok {
						replaceEmptyStructsAndSlicesWithNil(elemMap)
						if len(elemMap) > 0 {
							allElementsEmpty = false
						}
					} else {
						allElementsEmpty = false
					}
				}
				if allElementsEmpty {
					m[k] = nil
				}
			}
		}
	}
}