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

feat(echo): add dynamic path support for echo endpoint #271

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

jjchambl
Copy link
Contributor

@jjchambl jjchambl commented Jun 7, 2023

This pull request seeks to add dynamic path support for both the echo and api/echo endpoints, so that echo/test is also routed to the echo handler, as is echo/test/test.

In addition, I've added support for PUT operations to this endpoint.

Comment on lines 103 to 104
s.router.HandleFunc("/echo", s.echoHandler).Methods("POST,PUT")
s.router.HandleFunc("/echo/{echo:.*}", s.echoHandler).Methods("POST,PUT")
Copy link

Choose a reason for hiding this comment

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

Suggestions:

  • What about using PathPrefix() to allow "/echo/{anyPath}"?
  • What about accepting all HTTP methods, e.g. not restricting these paths to specific methods?
Suggested change
s.router.HandleFunc("/echo", s.echoHandler).Methods("POST,PUT")
s.router.HandleFunc("/echo/{echo:.*}", s.echoHandler).Methods("POST,PUT")
s.router.Path("/echo").HandlerFunc(s.echoHandler)
s.router.PathPrefix("/echo/").HandlerFunc(s.echoHandler)

Comment on lines 123 to 124
s.router.HandleFunc("/api/echo", s.echoHandler).Methods("POST,PUT")
s.router.HandleFunc("/api/echo{echo:.*}", s.echoHandler).Methods("POST,PUT")
Copy link

@merusso merusso Jun 7, 2023

Choose a reason for hiding this comment

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

This should be consistent with the path patterns used above (currently api/echo{echo:.*} vs /echo/{echo:.*})

Copy link
Contributor Author

@jjchambl jjchambl Jun 8, 2023

Choose a reason for hiding this comment

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

This should be consistent with the path patterns used above (currently api/echo{echo:.} vs /echo/{echo:.})

This is consistent with the previous route paths; both /api/echo and /echo were exposed previously.

@jjchambl
Copy link
Contributor Author

@stefanprodan bumping this PR; happy to make changes as needed.

Copy link
Owner

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @jjchambl

@stefanprodan stefanprodan merged commit 7d13025 into stefanprodan:master Jun 22, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants