Skip to content

Commit

Permalink
Merge pull request #22 from BadKid90s/name
Browse files Browse the repository at this point in the history
refactor(main): 修改方法命名
  • Loading branch information
BadKid90s authored May 13, 2024
2 parents 2130cba + 6f2225f commit a534c1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions example/matcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func main() {
chain.Use(recover.Recover())

//添加响应头是否存在匹配器的自定义中间件
chain.UseMatcher(header.ResponseExists("token"), func(context *knife.Context) {
chain.UseMatcher(header.RespExists("token"), func(context *knife.Context) {
log.Printf("token middleware,token:%s ", context.Writer.Header().Get("token"))
context.Next()
})

//添加带有组合匹配器的自定义中间件
chain.UseMatcher(combination.Any(header.ResponseExists("token"), header.ResponseExists("auth")), func(context *knife.Context) {
chain.UseMatcher(combination.Any(header.RespExists("token"), header.RespExists("auth")), func(context *knife.Context) {
log.Printf("token middleware,token:%s ", context.Writer.Header().Get("token"))
context.Next()
})
Expand Down
16 changes: 8 additions & 8 deletions knife/matcher/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@ import (
"net/http"
)

func ResponseExists(key string) knife.MiddlewareMatcher {
func RespExists(key string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return !equalHeaderValue(response.Header(), key, "")
}
}

func ResponseNotExists(key string) knife.MiddlewareMatcher {
func RespNotExists(key string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return equalHeaderValue(response.Header(), key, "")
}
}

func ResponseNe(key, value string) knife.MiddlewareMatcher {
func RespNe(key, value string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return !equalHeaderValue(response.Header(), key, value)
}
}

func ResponseEq(key, value string) knife.MiddlewareMatcher {
func RespEq(key, value string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return equalHeaderValue(response.Header(), key, value)
}
}

func RequestExists(key string) knife.MiddlewareMatcher {
func ReqExists(key string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return !equalHeaderValue(request.Header, key, "")
}
}

func RequestNotExists(key string) knife.MiddlewareMatcher {
func ReqNotExists(key string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return equalHeaderValue(request.Header, key, "")
}
}

func HeaderRequestNe(key, value string) knife.MiddlewareMatcher {
func ReqNe(key, value string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return !equalHeaderValue(request.Header, key, value)
}
}

func HeaderRequestEq(key, value string) knife.MiddlewareMatcher {
func ReqEq(key, value string) knife.MiddlewareMatcher {
return func(response knife.HttpResponseWriter, request knife.HttpRequest) bool {
return equalHeaderValue(request.Header, key, value)
}
Expand Down

0 comments on commit a534c1b

Please sign in to comment.