增加比较两个map某一个字段值是否相等的能力 #4

Merged
zhangdeman merged 5 commits from feature/diff into master 2024-03-08 16:00:00 +08:00
Showing only changes of commit c07adaf249 - Show all commits

View File

@ -30,11 +30,23 @@ func (d *diff) Compare(fieldList []string, input wrapper.Map, storage wrapper.Ma
} }
res := make(map[string]*define.DiffResult) res := make(map[string]*define.DiffResult)
for _, itemField := range fieldList { for _, itemField := range fieldList {
if compareFunc, exist := option.CustomDiffFuncTable[itemField]; exist && nil != compareFunc { res[itemField] = d.CompareSingle(itemField, input, storage, option)
res[itemField] = compareFunc(itemField, input, storage, option)
} else {
res[itemField] = define.DefaultDiffFunc(itemField, input, storage, option)
}
} }
return res 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)
}
}