Compare commits
2 Commits
a87a97b0e8
...
5a2df69ffe
Author | SHA1 | Date | |
---|---|---|---|
5a2df69ffe | |||
d5d65c366b |
@ -41,4 +41,6 @@ type EasyMap interface {
|
||||
ToStruct(receiver interface{}) error
|
||||
// ToString 转为字符串
|
||||
ToString() string
|
||||
// Filter 过滤数据
|
||||
Filter(ignoreFieldList []string, rewriteFieldTable map[string]interface{}) map[string]interface{}
|
||||
}
|
||||
|
25
common.go
25
common.go
@ -374,3 +374,28 @@ func (c *common) ToString() string {
|
||||
mapData := c.GetAllForMapKeyString()
|
||||
return serialize.JSON.MarshalForString(mapData)
|
||||
}
|
||||
|
||||
// Filter 对数据进行过滤
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:25 2024/3/8
|
||||
func (c *common) Filter(ignoreFieldList []string, rewriteFieldTable map[string]string) map[string]interface{} {
|
||||
result := make(map[string]interface{})
|
||||
ignoreFieldTable := make(map[string]bool)
|
||||
for _, item := range ignoreFieldList {
|
||||
ignoreFieldTable[item] = true
|
||||
}
|
||||
data := c.GetAllForMapKeyString()
|
||||
for field, val := range data {
|
||||
if _, exist := ignoreFieldTable[field]; exist {
|
||||
// 忽略当前字段
|
||||
continue
|
||||
}
|
||||
if rewriteField, exist := rewriteFieldTable[field]; exist && len(rewriteField) > 0 {
|
||||
field = rewriteField
|
||||
}
|
||||
result[field] = val
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user