Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(main): 修改方法命名 #22

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading