-
Notifications
You must be signed in to change notification settings - Fork 438
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
fix #49; implement gin adapter #82
Conversation
And could you please add the document to https://github.com/sentinel-group/sentinel-website/tree/master/docs/zh-cn/golang? |
adapter/gin/middleware.go
Outdated
func SentinelMiddleware(opts ...Option) gin.HandlerFunc { | ||
options := evaluateOptions(opts) | ||
return func(c *gin.Context) { | ||
resourceName := c.Request.Method + ":" + c.Request.URL.Path |
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.
Maybe here we need c.FullPath()
to get the matched route path (e.g. /foo/:id
) rather than the actual path (to avoid generating too many URL entries, bringing memory footprint). And as the comments say:
FullPath returns a matched route full path. For not found routes returns an empty string.
So when the FullPath()
returns the empty string, we could just skip it.
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.
Actually we did this by customizing an extractor and matcher.
But in the latest version, the FullPath method is provided, so we can use it directly.
Thank you for pointing it out :)
adapter/gin/middleware.go
Outdated
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// SentinelMiddleware |
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.
Could you please improve the comment here?
adapter/gin/middleware_test.go
Outdated
|
||
_, err = flow.LoadRules([]*flow.FlowRule{ | ||
{ | ||
Resource: "GET_/ping", |
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.
GET:/ping
?
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
Nice work. Thanks for contributing! |
Describe what this PR does / why we need it
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews