Skip to content

Commit

Permalink
support broad string for middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sjqzhang committed Nov 3, 2023
1 parent a7aea11 commit 97e9526
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,14 @@ func parseMiddlewareAnnotations(annotations string) []middleware {

var middlewares []middleware


spliterReg:=regexp.MustCompile(`\w+\s*(\([^)]+\))|\w+\s*(\{[^\}]+\})|\w+`)

// 分隔多个中间件
middlewareList := strings.Split(annotations, ";")
middlewareList := spliterReg.FindAllString(annotations, -1)

// 正则表达式用于匹配参数
paramRegexMatch := regexp.MustCompile(`(\([^\)]+\))`)
paramRegexMatch := regexp.MustCompile(`(\([^\)]+\))|\{([^\}]+)\}`)

paramRegex := regexp.MustCompile(`(\w+)\s*=\s*("[^"]+?")|(\w+)\s*=\s*('[^']+?')|(\w+)\s*=\s*([^,]+)`)

Expand Down
28 changes: 28 additions & 0 deletions gen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gdi

import (
"fmt"
"testing"
)

func Test_parseMiddlewareAnnotations(t *testing.T) {

txt:=`xxx,name {tt=10,xx="sdfdf"},xxx,cache {name=dfd, adf="ad f" } ,xxxa,xx(asd="sd fd"")`

mids:=parseMiddlewareAnnotations(txt)

for _,v:=range mids{
fmt.Println(v.Name)
v.Params.Range(func(key, value interface{}) bool {
t.Log( fmt.Sprintf(`"%s" "%v" "%v"` , v.Name,key,value))
return true
})

}

if len(mids)!=6{
t.Error("error")
}


}

0 comments on commit 97e9526

Please sign in to comment.