-
-
Notifications
You must be signed in to change notification settings - Fork 66
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: path parsing issue #371
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you for the PR! 🥳
Add some tests and documentation (/documentation
folder) please.
func NewRoute[T, B any](method, path string, handler any, e *Engine, options ...func(*BaseRoute)) Route[T, B] { | ||
func NewRoute[T, B any](method, path string, handler any, e *Engine, config RouteConfig, options ...func(*BaseRoute)) Route[T, B] { | ||
if config.StripTrailingSlash && len(path) > 1 { | ||
path = strings.TrimRight(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.
Please don't change the Route signature, and add it as an option
as the other ones
type RouteConfig struct { | ||
StripTrailingSlash bool | ||
} | ||
|
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.
Use a Route Option please, cf the BaseRoute
struct and the option.go
file
if s.StripTrailingSlash && len(r.URL.Path) > 1 { | ||
r.URL.Path = strings.TrimRight(r.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.
Is the length condition useful?
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.
Yes it is, to avoid strip a route like '/'
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.
Mmmh good idea! Can you make this comparison more explicit?
|
||
// StripTrailingSlash determines if trailing slashes should be removed from routes and requests | ||
StripTrailingSlash bool |
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.
Please just use a route option, you can delete it here
close #366
@EwenQuim
I introduced a new server property
StripTrailingSlash
that can be activated by usingwithStripTrailingSlash
this helps remove trailing slash from defined routes and request