diff --git a/example/matcher/main.go b/example/matcher/main.go index 6019662..e6c3129 100644 --- a/example/matcher/main.go +++ b/example/matcher/main.go @@ -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() }) diff --git a/knife/matcher/header/header.go b/knife/matcher/header/header.go index 88f0981..8bfb15f 100644 --- a/knife/matcher/header/header.go +++ b/knife/matcher/header/header.go @@ -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) }