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
middleware/selector #1244
Merged
Merged
middleware/selector #1244
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
需要支持client不? |
要的 |
tonybase
reviewed
Jul 25, 2021
添加了client的middleware 用断言的方式支持数组匹配了 如果继续用字符串,只是一个类型断言的影响 性能影响应该很小 |
http.Middleware(
selector.Client(logging.Server(), authjwt.Server())
.Prefix("/article.", "/login")
.Regex("/article.{List*}"),
.Path("/article.ListCategory"),
)
http.Middleware(
selector.Server(logging.Server(), authjwt.Server())
.Prefix("/article.", "/login")
.Regex("/article.{List*}"),
.Path("/article.ListCategory"),
)
type Builder strcut {
client bool
prefix []string
regex []string
path []string
}
func Client(ms ...middleware.Middleware) *Builder {
return &Builder{client: true}
}
func (b *Builder) Prefix(prefix ...string) { b.prefix = prefix }
func (b *Builder) Regex(regex ...string) { b.regex = regex }
func (b *Builder) Path(path ...string) { b.path = path } |
现在的用法是: http.Middleware(
selector.Server().Regex("/hi/[0-9]+").Prefix("/hello/").Path("/hello/kratos", "/hi/kratos").Build(),
)
http.Middleware(
selector.Server().NotRegex("/hi/[0-9]+").NotPrefix("/hello/").NotPath("/hello/kratos", "/hi/kratos").Build(),
) 现在的问题是正向匹配和反向匹配(比如:notPrefix ) 不能同时存在 目前做法是panic了 可能有些激进 可以默认正向匹配或者反向匹配 |
不然把反向去掉?必须明确地配置,也比较简单一些 |
但是有可能除了一两个路由都要用 这个中间件 那得配置多少个啊 你考虑一下吧! |
prefix match还好的,配置好需要支持的前缀就好 |
好的 那我去掉 |
tonybase
approved these changes
Jul 25, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM! |
elvizlai
pushed a commit
to elvizlai/kratos
that referenced
this pull request
Aug 2, 2021
* middleware selector client and support array
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#1241