-
Notifications
You must be signed in to change notification settings - Fork 269
Adding new helper functions to internal.HTTPClient API #269
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
Conversation
URL string | ||
Body HTTPEntity | ||
Opts []HTTPOption | ||
SuccessFn SuccessFn |
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.
It's kinda weird for both HTTPClient
and Request
to have so many fields in common. Would it make sense to package them into a separate struct that they each get a pointer to?
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.
The problem with that is, callers have to use another level of nesting to specify common properties:
req := &internal.Request{
CommonSettings: &internal.CommonSettings{
SuccessFn: mySuccessFn,
},
}
I'd prefer following over that:
req := &internal.Request{
SuccessFn: mySuccessFn,
}
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.
That's fair.
I do feel like these http methods have probably gotten more complicated than they need to be, and maybe we got some abstraction wrong that's making thing needlessly difficult. But I don't have any specific objections to this change. Certainly nothing worth holding this PR up any longer.
But I think we should brainstorm how to clean this up at some point.
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
The pattern of making a JSON HTTP request, parsing the response and handling errors is very common in the SDK. This PR introduces a new
DoAndUnmarshal()
helper function tointernal.HTTPClient
to implement this pattern. Also includes:CreateErrFn
andSuccessFn
options.ErrParser
option, and theCheckStatus()
andUnmarshal()
functions on theResponse
.