| 13 | } |
| 14 | |
| 15 | func compareValues(old, new interface{}) Diff { |
| 16 | if reflect.TypeOf(old) != reflect.TypeOf(new) { |
| 17 | |
| 18 | // In YAML there is no difference between "" and null |
| 19 | if old == "" && new == nil { |
| 20 | return value{new, Unchanged} |
| 21 | } |
| 22 | |
| 23 | return value{new, Changed} |
| 24 | } |
| 25 | |
| 26 | switch v := old.(type) { |
| 27 | case []interface{}: |
| 28 | return compareSlices(v, new.([]interface{})) |
| 29 | case map[string]interface{}: |
| 30 | return CompareMaps(v, new.(map[string]interface{})) |
| 31 | default: |
| 32 | if !reflect.DeepEqual(old, new) { |
| 33 | return value{new, Changed} |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return value{old, Unchanged} |
| 38 | } |
| 39 | |
| 40 | func compareSlices(old, new []interface{}) Diff { |
| 41 | max := int(math.Max(float64(len(old)), float64(len(new)))) |