-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Rework body handling to use providers #23
Conversation
var body io.Reader = nil | ||
|
||
if s.body != nil { | ||
body, err = s.body.Body() |
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.
You can call it s.bodyProvider
to avoid the double body awkwardness.
body, err := s.getRequestBody() | ||
if err != nil { | ||
return nil, err | ||
var body io.Reader = nil |
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.
nil is the default
Thanks. I like the refactor in general, though I'd prefer the multipart code be split into a separate review. I'll set aside time to consider it in depth wrt. other APIs, whereas the refactor by itself to use BodyProvider is more straight forward to merge. Then in the short term you could use your customer Provider too. How about sticking with |
"io" | ||
"io/ioutil" | ||
"strings" | ||
|
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.
stdlib packages can all be clumped together
Great ! I'll get working on it.
Actually I used |
Re-reading my original comment for Body, it looks like the reason for the
I don't think a type assertion attempt and NopCloser wrap at the time of setting the body are required though. It looks like |
Incidentally, also add support for multipart and file uploading.
@dghubble right ! I updated the PR to handle your feedback. |
Awesome. I've added a tweak in #25 to keep the Thanks! |
Merged in #25 |
Hi !
Currently, sling only handles JSON, form and raw reader bodies.
These 3 types are hard coded in the Sling struct, by having one field for every type.
While it was still possible to send other types of bodies (xml, multipart, ...), their usage wasn't as fluent as the other 3 types.
This PR proposes the following:
BodyProvider
interfaceAdding support for a new body types would not require touching the Sling struct. Simply a new implementation of the interface and maybe a factory function would do.
Users wanting to handle other types can simply implement the
BodyProvider
and use the API as seamlessly as the baked-in types:The code in this PR is not finished (it could use some more polish and tests).
I just wanted to get your feedback on this proposal before investing more time and effort on it.