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

Logger skip paths allow params #3144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hanyucui
Copy link

@hanyucui hanyucui commented May 6, 2022

This change adds support for skip paths with params, e.g.,
"/user/:id". This is more flexible and the implementation is simply
comparing Context.FullPath() rather than Context.Request.URL.Path
against skip paths.

The only case where it would lead to regression is where legacy code
uses hardcoded paths for parameterized paths. E.g., when hardcoded
paths like "/user/1" and "/user/2" are added to skipped paths for
"/user/:id". Although legal, I cannot imagine when such a case
would be useful. Hence I think regression would be extremely rare in
practice.

This change also updates relevant tests.

@hanyucui hanyucui changed the title Logger skip paths use Context.fullPath [WIP] Logger skip paths use Context.fullPath May 7, 2022
@hanyucui hanyucui changed the title [WIP] Logger skip paths use Context.fullPath Logger skip paths allow params May 10, 2022
This is more flexible and is breaking only in
very rare cases.

Restore original behavior

Update logger path skipping tests
@hanyucui hanyucui marked this pull request as ready for review May 10, 2022 04:47
@hanyucui
Copy link
Author

@appleboy @thinkerou Please take a look. Thanks in advance!

1 similar comment
@hanyucui
Copy link
Author

@appleboy @thinkerou Please take a look. Thanks in advance!

@appleboy appleboy added this to the v1.9 milestone Jul 13, 2022

PerformRequest(router, "GET", "/logged")
assert.Contains(t, buffer.String(), "200")

buffer.Reset()
PerformRequest(router, "GET", "/loggedUsers/2")
assert.Contains(t, buffer.String(), "200")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert.Contains(t, "200", buffer.String())

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for leaving your feedback @appleboy. I just want to confirm this is the change your want, since the current code base adopts the convention of assert.Contains(t, buffer.String(), "200"). I will change them all once confirmed. Let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hanyucui sorry for my mistake. you are right.

func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for double-checking, @appleboy. Let me know if other changes are needed.

router.GET("/skipped", func(c *Context) {})
router.GET("/skippedUsers/:id", func(c *Context) {})

PerformRequest(router, "GET", "/logged")
assert.Contains(t, buffer.String(), "200")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert.Contains(t, "200", buffer.String())

router.GET("/skipped", func(c *Context) {})
router.GET("/skippedUsers/:id", func(c *Context) {})

PerformRequest(router, "GET", "/logged")
assert.Contains(t, buffer.String(), "200")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert.Contains(t, "200", buffer.String())


PerformRequest(router, "GET", "/logged")
assert.Contains(t, buffer.String(), "200")

buffer.Reset()
PerformRequest(router, "GET", "/loggedUsers/2")
assert.Contains(t, buffer.String(), "200")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert.Contains(t, "200", buffer.String())

@appleboy appleboy modified the milestones: v1.9, v1.10 Feb 14, 2023
@appleboy
Copy link
Member

Change milestone to v1.10

@appleboy appleboy modified the milestones: v1.10, v1.11 Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants