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

Use net/http constants instead of string literals for HTTP verbs #587

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Jun 14, 2018

Switches from string literals like "GET" over to their corresponding
constants in net/http like http.MethodGet. This isn't a huge win,
but seems like slightly better hygiene and slightly reduces the risk of
typos because a mistyped verb will now not compile instead of crashing
on a test or at runtime.

For review: I basically did a project-wide find and replace, so me
accidentally screwing up a verb change is relatively unlikely.

r? @remi-stripe
cc @stripe/api-libraries

Switches from string literals like `"GET"` over to their corresponding
constants in `net/http` like `http.MethodGet`. This isn't a huge win,
but seems like slightly better hygiene and slightly reduces the risk of
typos because a mistyped verb will now not compile instead of crashing
on a test or at runtime.
@@ -1,6 +1,8 @@
package account

import (
"net/http"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to possibly pre-empt some feedback: net/http is new in all client packages, but they were already depending on it transitively through the top-level stripe package, so I don't think including it in all of these will have any meaningful effect on final binary size.

@@ -240,7 +240,7 @@ func (s *BackendConfiguration) CallRaw(method, path, key string, form *form.Valu
var body io.Reader
if form != nil && !form.Empty() {
data := form.Encode()
if strings.ToUpper(method) == "GET" {
if method == http.MethodGet {
Copy link
Contributor

Choose a reason for hiding this comment

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

I stripped the ToUpper here — all calls now use net/http constants so it should be perfectly safe to just compare it directly against http.MethodGet now.

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

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

LGTM

@brandur-stripe
Copy link
Contributor

Thank you as usual Remi!

@brandur-stripe brandur-stripe merged commit 211a283 into master Jun 14, 2018
@brandur-stripe brandur-stripe deleted the brandur-http-constants branch June 14, 2018 19:07
@brandur-stripe
Copy link
Contributor

Released as 34.3.0.

nadaismail-stripe pushed a commit that referenced this pull request Oct 18, 2024
* added fixes for security scan issues

* fixed empty exception list check

* changed empty list check order

* fixing deprecated  var name

* fix for failing test class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants