Skip to content

Commit

Permalink
refactor: check if leaf node
Browse files Browse the repository at this point in the history
  • Loading branch information
hui.wang committed Jan 10, 2022
1 parent 724f7de commit 8610eb4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import (
// 要求fieldPathMap是基于`空`结构数据生成,否则对MAP结构信息判断会造成影响
func isLeafFieldPath(fieldPathMap map[string]StructFieldPathInfo, fieldPath string) bool {
prefix := fieldPath + DefaultKeyDelim //避免两个字段但是拥有共同前缀,如TypeMapStringInt TypeMapStringIntNotLeaf
for k, v := range fieldPathMap {
for k := range fieldPathMap {
if strings.HasPrefix(k, prefix) {
// k是fieldPath的子节点,则fieldPath不指向叶子节点
return false
}
if k == fieldPath && v.TagList.HasIgnoreCase(xfield.TagNotLeaf) {
return false
}
}

// 没有找到fieldPath.为前缀的节点,可能是一个基础类型,slice或者是一个map,map可能是一个非叶子节点,通过是否配置了xfield.TagNotLeaf标签决定
if field, ok := fieldPathMap[fieldPath]; ok && field.TagList.HasIgnoreCase(xfield.TagNotLeaf) {
return false
}

return true
}

Expand Down

0 comments on commit 8610eb4

Please sign in to comment.