providers: Change the signature of NewRequest to accept body as interface{} #1053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The providers.REST interface defined a NewRequest() method that was
implemented by the generic HTTP REST provider as well as the github REST
provider. However, the two implementations treat the body of the request
a bit differently - the HTTP REST provider treats the body as a generic
io.Reader
which was also exposed in the high level interface, but thegithub NewRequest treats the body as an interface that can be
JSON-encoded.
And because io.Reader doesn't really encode to JSON easily, but expects to be
able to infer the types from the
interface it's encoding, I think it's better to just expose
interface{}
inthe high-level provider interface and let the lower-level implementation deal
with the conversion. This way the caller would know to pass e.g.
map[string]any
instead of plain io.Reader.If we want to keep the reader in the high level interface, then another
option might be to encode the io.Reader into map[string]any in the
RestClient.NewRequest
method.