Skip to content

Commit

Permalink
修复对interface{}类型的支持 ,解决代码冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-cn committed Jan 11, 2023
1 parent a40d4ed commit d459a50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
39 changes: 26 additions & 13 deletions test/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
)

type Users struct {
UID uint `json:"uid,select(article)"` //select中表示选中的场景(该字段将会使用到的场景)
Avatar string `json:"avatar,select(article)"` //和上面一样此字段在article接口时才会解析该字段
UID uint `json:"uid,select(article),omit(article)"` //select中表示选中的场景(该字段将会使用到的场景)
Avatar string `json:"avatar,select(article),omit(article)"` //和上面一样此字段在article接口时才会解析该字段

Nickname string `json:"nickname,select(article|profile)"` //"|"表示有多个场景都需要这个字段 article接口需要 profile接口也需要

Sex int `json:"sex,select(profile)"` //该字段是仅仅profile才使用
VipEndTime time.Time `json:"vip_end_time,select(profile)"` //同上
Price string `json:"price,select(profile)"` //同上
Sex int `json:"sex,select(profile)"` //该字段是仅仅profile才使用
VipEndTime time.Time `json:"vip_end_time,select(profile),omit(article)"` //同上
Price string `json:"price,select(profile)"` //同上

Hobby string `json:"hobby,omitempty,select($any)"` //任何场景下为空忽略
Lang []LangAge `json:"lang,omitempty,select($any)"` //任何场景下为空忽略
Hobby string `json:"hobby,omitempty,select($any)"` //任何场景下为空忽略
Lang []LangAge `json:"lang,omitempty,select($any),omit(article)"` //任何场景下为空忽略
}

type LangAge struct {
Expand Down Expand Up @@ -48,29 +48,42 @@ func newUsers() Users {

var str string

func BenchmarkUserPointer(b *testing.B) {
func BenchmarkOmitPointerWithCache(b *testing.B) {
user := newUsers()
filter.EnableCache(true)
for i := 0; i < b.N; i++ {
_ = filter.SelectMarshal("article", &user)
_ = filter.Omit("article", &user)
}
}

func BenchmarkUserPointerWithCache(b *testing.B) {
func BenchmarkSelectPointerWithCache(b *testing.B) {
user := newUsers()
filter.EnableCache(true)
for i := 0; i < b.N; i++ {
_ = filter.Select("article", &user)
}
}

func BenchmarkUserVal(b *testing.B) {
func BenchmarkOmitVal(b *testing.B) {
user := newUsers()
filter.EnableCache(false)
for i := 0; i < b.N; i++ {
_ = filter.SelectMarshal("article", user)
_ = filter.Omit("article", user)
}
}
func BenchmarkUserValWithCache(b *testing.B) {
func BenchmarkSelectVal(b *testing.B) {
user := newUsers()
filter.EnableCache(false)
for i := 0; i < b.N; i++ {
_ = filter.Select("article", user)
}
}

func BenchmarkAll(b *testing.B) {
for i := 0; i < b.N; i++ {
b.Run("BenchmarkOmitPointerWithCache", BenchmarkOmitPointerWithCache)
b.Run("BenchmarkOmitVal", BenchmarkOmitVal)
b.Run("BenchmarkSelectPointerWithCache", BenchmarkSelectPointerWithCache)
b.Run("BenchmarkSelectVal", BenchmarkSelectVal)
}
}
3 changes: 0 additions & 3 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func (u *Us) GetAvatar2() string {
}

func main() {
fmt.Println(filter.Omit("1111", Us2{Data: map[string]interface{}{
"1": 1,
}}))

//var bb = []byte(`{"a":"1"}`)
u := Us{
Expand Down

0 comments on commit d459a50

Please sign in to comment.