Documentation
¶
Index ¶
- Constants
- Variables
- type BytesErrorBody
- type Client
- func (c *Client) AddOptions(opts ...Option)
- func (c *Client) DoReq(req *http.Request, opts ...RespOption) (*http.Response, error)
- func (c *Client) Extend(opts ...Option) *Client
- func (c *Client) JSON(req *http.Request, obj any, opts ...RespOption) (*http.Response, error)
- func (c *Client) Stream(req *http.Request, w io.Writer) (int64, error)
- func (c *Client) Unwrap() *http.Client
- type Config
- type ErrorHandler
- type HeaderLayer
- type JSONErrorBody
- type JsonUnmarshaler
- type Layer
- type Option
- func WithBytesError() Option
- func WithCheckRedirect(fn func(req *http.Request, via []*http.Request) error) Option
- func WithCookieJar(jar http.CookieJar) Option
- func WithCustomJSONError[E error]() Option
- func WithErrorHandler(h ErrorHandler) Option
- func WithHeaders(h http.Header) Option
- func WithJSONError() Option
- func WithLayer(l Layer) Option
- func WithTimeout(t time.Duration) Option
- func WithTransport(t *http.Transport) Option
- type RespOption
Constants ¶
View Source
const DefaultTimeout = 30 * time.Second
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BytesErrorBody ¶
type BytesErrorBody []byte
func (BytesErrorBody) Error ¶
func (e BytesErrorBody) Error() string
type HeaderLayer ¶
type HeaderLayer struct {
// contains filtered or unexported fields
}
type JSONErrorBody ¶
func (JSONErrorBody) Error ¶
func (e JSONErrorBody) Error() string
type JsonUnmarshaler ¶
type Layer ¶
type Layer func(base http.RoundTripper) http.RoundTripper
type Option ¶
type Option func(cfg *Config)
func WithBytesError ¶
func WithBytesError() Option
func WithCheckRedirect ¶
func WithCookieJar ¶
func WithCustomJSONError ¶
func WithErrorHandler ¶
func WithErrorHandler(h ErrorHandler) Option
func WithHeaders ¶
func WithJSONError ¶
func WithJSONError() Option
func WithTimeout ¶
func WithTransport ¶
type RespOption ¶
RespOption is an option to handle a successful http.Response pointer. Aborts if the first option returns an error. The response's body is already read and closed. The read data is passed as parameter.
func WithCopy ¶
func WithCopy(w io.Writer) RespOption
WithCopy copies the body of the http.Response to the given io.Writer.
func WithJSON ¶
func WithJSON(obj any) RespOption
WithJSON unmarshalls the body of the http.Response into the given object using the Config.JsonUnmarshal function.
func WithStatusCode ¶
func WithStatusCode(code int) RespOption
WithStatusCode checks if the http.Response matches the given HTTP status code. Returns an error if the status code does not match.
Click to show internal directories.
Click to hide internal directories.