Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RequestBody ¶
Represents a request body.
If the provided request data is an io.Reader, DebugBytes is set to "<io.Reader>". Otherwise, DebugBytes is set to the marshaled JSON representation of the request data, and ReadCloser is set to a new io.ReadCloser that reads from DebugBytes.
Request bodies are never closed by the client, hence only accepting io.Reader.
func NewRequestBody ¶
func NewRequestBody(data any) (RequestBody, error)
func (RequestBody) Reset ¶
func (r RequestBody) Reset() error
Reset a request body to its initial state.
This is used to retry requests with a body that has already been read. If the request body is not resettable (i.e. not nil and of type other than strings.Reader or bytes.Reader), this will return an error.
type ResponseWrapper ¶
type ResponseWrapper struct { // ReadCloser is the response body that was received from the server. ReadCloser io.ReadCloser // DebugBytes is the raw response body that was received from the server, if // the response was not streamed. DebugBytes []byte // Response is the original http.Response object. Response *http.Response // RequestBody is the request body that was sent to the server. RequestBody RequestBody }
Represents a response.
Responses must always be closed. For non-streaming responses, they are closed during deserialization in the client (see unmarshall()). For streaming responses, they are returned to the caller, who is responsible for closing them. When debugging is enabled, the value of DebugBytes is printed when logging the response body.
func NewResponseWrapper ¶
func NewResponseWrapper(r *http.Response, req RequestBody) (ResponseWrapper, error)
NewResponseWrapper creates a new ResponseWrapper from an http.Response.
If the response is nil, or the response body is nil, this will return an error.
If the response is a streaming response, the response body will be returned as-is. Otherwise, the response body will be read into memory and returned as a byte slice. Streaming responses are identified by the "Accept" request header being set to anything other than "application/json" and the "Content-Type" header being set to "application/json".