-
Notifications
You must be signed in to change notification settings - Fork 470
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
Conversation
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" |
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.
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 { |
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.
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.
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.
LGTM
Thank you as usual Remi! |
Released as 34.3.0. |
* 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
Switches from string literals like
"GET"
over to their correspondingconstants in
net/http
likehttp.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