增加比较两个map某一个字段值是否相等的能力 #4
22
tool/diff.go
22
tool/diff.go
@ -30,11 +30,23 @@ func (d *diff) Compare(fieldList []string, input wrapper.Map, storage wrapper.Ma
|
||||
}
|
||||
res := make(map[string]*define.DiffResult)
|
||||
for _, itemField := range fieldList {
|
||||
if compareFunc, exist := option.CustomDiffFuncTable[itemField]; exist && nil != compareFunc {
|
||||
res[itemField] = compareFunc(itemField, input, storage, option)
|
||||
} else {
|
||||
res[itemField] = define.DefaultDiffFunc(itemField, input, storage, option)
|
||||
}
|
||||
res[itemField] = d.CompareSingle(itemField, input, storage, option)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// CompareSingle 比较一个字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:57 2024/3/8
|
||||
func (d *diff) CompareSingle(field string, input wrapper.Map, storage wrapper.Map, option *define.DiffOption) *define.DiffResult {
|
||||
if nil == option {
|
||||
option = define.NewDiffOption()
|
||||
}
|
||||
if compareFunc, exist := option.CustomDiffFuncTable[field]; exist && nil != compareFunc {
|
||||
return compareFunc(field, input, storage, option)
|
||||
} else {
|
||||
return define.DefaultDiffFunc(field, input, storage, option)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user