-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare.go
More file actions
54 lines (48 loc) · 1.21 KB
/
compare.go
File metadata and controls
54 lines (48 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package wineregdiff
type DataComparator interface {
CompareData(name DataName, data1, data2 Data) (bool, error)
}
type DefaultDataComparator struct {
}
func (c *DefaultDataComparator) CompareData(name DataName, data1, data2 Data) (bool, error) {
if data1.DataType() != data2.DataType() {
return false, nil
}
return data1.String() == data2.String(), nil
}
type ValueComparator interface {
CompareValue(key Key, value1, value2 Value) (ValueDiff, error)
}
type DefaultValueComparator struct {
DataComparator DataComparator
IgnoreKeys []Key
}
func (c *DefaultValueComparator) CompareValue(key Key, value1, value2 Value) (ValueDiff, error) {
diff := NewValueDiff()
for _, ignoreKey := range c.IgnoreKeys {
if key == ignoreKey {
return diff, nil
}
}
for dataName, data1 := range value1 {
data2, ok := value2[dataName]
if !ok {
diff.Value1[dataName] = data1
continue
}
equals, err := c.DataComparator.CompareData(dataName, data1, data2)
if err != nil {
return diff, err
}
if !equals {
diff.Value1[dataName] = data1
diff.Value2[dataName] = data2
}
}
for dataName, data2 := range value2 {
if _, ok := value1[dataName]; !ok {
diff.Value2[dataName] = data2
}
}
return diff, nil
}