Skip to content

Commit dfafc8f

Browse files
committed
开启缓存,更新文档
1 parent 8cb201d commit dfafc8f

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## English
99

10-
Golang's JSON field filter can select fields at will, output fields of specified structures at will, and reuse structures. **It fully supports generics** and is perfectly compatible with go 1.18 and 1.17 and below
10+
Golang's JSON field filter can select fields at will, output fields of specified structures at will, and reuse structures. **It fully supports generics** and is Compatible with all versions of go,The official json can support and be compatible with all json-filter
1111

1212
list:
1313

@@ -626,7 +626,7 @@ func UserRes(c *gin.Context) {
626626

627627
### 简体中文
628628

629-
golang的json字段过滤器,随意选择字段,随意输出指定结构体的字段,复用结构体,**全面支持泛型**对于go 1.18和1.17及其以下版本完美兼容
629+
golang的json字段过滤器,随意选择字段,随意输出指定结构体的字段,复用结构体,**全面支持泛型****对于go所有版本均完美兼容**,官方json库能做的json-filter全部兼容和支持
630630

631631
视频教程快速入门:https://www.bilibili.com/video/BV1ba411b7m1/
632632

filter/filter.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package filter
22

3+
import "fmt"
4+
35
type Filter struct {
46
node *fieldNodeTree
57
}
@@ -35,13 +37,19 @@ func (f Filter) JSON() (string, error) {
3537
func (f Filter) String() string {
3638
json, err := f.JSON()
3739
if err != nil {
38-
return "[Filter Err]"
40+
return fmt.Sprintf("Filter Err: %s", err.Error())
3941
}
4042
return json
4143
}
4244

4345
// SelectMarshal 第一个参数填你结构体select标签里的场景,第二个参数是你需要过滤的结构体对象,如果字段的select标签里标注的有该场景那么该字段会被选中。
4446
func SelectMarshal(selectScene string, el interface{}) Filter {
47+
if enableCache {
48+
return selectWithCache(selectScene, el)
49+
}
50+
return selectMarshal(selectScene, el)
51+
}
52+
func selectMarshal(selectScene string, el interface{}) Filter {
4553
tree := &fieldNodeTree{
4654
Key: "",
4755
ParentNode: nil,
@@ -52,17 +60,12 @@ func SelectMarshal(selectScene string, el interface{}) Filter {
5260
}
5361
}
5462

55-
// Select 直接返回过滤后的数据结构,相当于直接SelectMarshal后再调用Interface方法
56-
//func Select(selectScene string, el interface{}) interface{} {
57-
// return SelectMarshal(selectScene, el).Interface()
58-
//}
59-
6063
// Select 直接返回过滤后的数据结构,相当于直接SelectMarshal后再调用Interface方法
6164
func Select(selectScene string, el interface{}) interface{} {
6265
if enableCache {
6366
return selectWithCache(selectScene, el).Interface()
6467
}
65-
return SelectMarshal(selectScene, el).Interface()
68+
return selectMarshal(selectScene, el).Interface()
6669
}
6770

6871
// selectWithCache 直接返回过滤后的数据结构,相当于直接SelectMarshal后再调用Interface方法
@@ -82,11 +85,18 @@ func Omit(omitScene string, el interface{}) interface{} {
8285
if enableCache {
8386
return omitWithCache(omitScene, el).Interface()
8487
}
85-
return OmitMarshal(omitScene, el).Interface()
88+
return omitMarshal(omitScene, el).Interface()
8689
}
8790

8891
// OmitMarshal 第一个参数填你结构体omit标签里的场景,第二个参数是你需要过滤的结构体对象,如果字段的omit标签里标注的有该场景那么该字段会被过滤掉
8992
func OmitMarshal(omitScene string, el interface{}) Filter {
93+
if enableCache {
94+
return omitWithCache(omitScene, el)
95+
}
96+
return omitMarshal(omitScene, el)
97+
}
98+
99+
func omitMarshal(omitScene string, el interface{}) Filter {
90100
tree := &fieldNodeTree{
91101
Key: "",
92102
ParentNode: nil,

test/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package main
22

33
func main() {
4-
54
}

0 commit comments

Comments
 (0)