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

Panic on unsupported HTTP method #2

Closed

Conversation

yurivish
Copy link
Contributor

@yurivish yurivish commented Apr 3, 2022

Right now it's possible for routes to be added to methods that will never be called. I happened to do this since the readme implicitly encouraged defining methods as strings, and I accidentally made a typo and saw that it wasn’t caught at runtime. This 3-line PR will identify the error and panic at route definition.

Thanks for writing this package, by the way – I'm learning how to develop web services in Go using your books and am considering using this router in a production setting since I expect my service won't be particularly CPU-bound and I enjoy the minimal-dependency life. :-)

Edit: Hmm, maybe the error message should say "invalid HTTP method" rather than "unsupported".

Edit 2: An alternative might be to change the example code to use http.MethodGet, which would make it impossible for this sort of typo to compile.

@yurivish
Copy link
Contributor Author

yurivish commented Apr 3, 2022

Actually, I'm not even sure this is a bug – the "typo" methods are indeed accessible via HTTP, and maybe there are niche uses cases for such functionality.

@yurivish yurivish closed this Apr 3, 2022
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.

1 participant