Documentation
¶
Index ¶
- Constants
- func CloneRequestBody(r *http.Request) ([]byte, error)
- func IsSuccessResponse(resp *http.Response) bool
- type BodyMarshaler
- type BodyUnmarshaler
- type EnrichedError
- type HttpClient
- func (c *HttpClient) Clone() *HttpClient
- func (c *HttpClient) NewConnectRequest(ctx context.Context, path string) *Request
- func (c *HttpClient) NewDeleteRequest(ctx context.Context, path string) *Request
- func (c *HttpClient) NewGetRequest(ctx context.Context, path string) *Request
- func (c *HttpClient) NewHeadRequest(ctx context.Context, path string) *Request
- func (c *HttpClient) NewOptionsRequest(ctx context.Context, path string) *Request
- func (c *HttpClient) NewPatchRequest(ctx context.Context, path string, body interface{}) *Request
- func (c *HttpClient) NewPostRequest(ctx context.Context, path string, body interface{}) *Request
- func (c *HttpClient) NewPutRequest(ctx context.Context, path string, body interface{}) *Request
- func (c *HttpClient) NewRequest(ctx context.Context, method, path string, body interface{}) *Request
- func (c *HttpClient) NewTraceRequest(ctx context.Context, path string) *Request
- func (c *HttpClient) SetBodyMarshaler(marshaler BodyMarshaler) *HttpClient
- func (c *HttpClient) SetBodyUnmarshaler(unmarshaler BodyUnmarshaler) *HttpClient
- func (c *HttpClient) SetDumpOnError() *HttpClient
- func (c *HttpClient) SetHeader(key, value string) *HttpClient
- func (c *HttpClient) SetHeaders(headers map[string]string) *HttpClient
- func (c *HttpClient) SetOnRequestReady(onRequestReady OnRequestReadyHook) *HttpClient
- func (c *HttpClient) SetOnResponseReady(onResponseReady OnResponseReadyHook) *HttpClient
- func (c *HttpClient) SetStackTraceEnabled(enabled bool) *HttpClient
- func (c *HttpClient) SetTimeout(timeout time.Duration) *HttpClient
- type JSONBodyMarshaler
- type JSONBodyUnmarshaler
- type NoopBodyMarshaler
- type OnRequestReadyHook
- type OnResponseReadyHook
- type Request
- func (r *Request) Do() (*http.Response, error)
- func (r *Request) SetBodyMarshaler(marshaler BodyMarshaler) *Request
- func (r *Request) SetBodyUnmarshaler(unmarshaler BodyUnmarshaler) *Request
- func (r *Request) SetDumpOnError() *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaders(headers map[string]string) *Request
- func (r *Request) SetOnRequestReady(onRequestReady OnRequestReadyHook) *Request
- func (r *Request) SetOnResponseReady(onResponseReady OnResponseReadyHook) *Request
- func (r *Request) SetStackTraceEnabled(enabled bool) *Request
- func (r *Request) WriteBodyTo(result interface{}) *Request
- type RequestOptions
- func (o *RequestOptions) Clone() *RequestOptions
- func (o *RequestOptions) SetBodyMarshaler(marshaler BodyMarshaler)
- func (o *RequestOptions) SetBodyUnmarshaler(unmarshaler BodyUnmarshaler)
- func (o *RequestOptions) SetDumpOnError()
- func (o *RequestOptions) SetHeader(key, value string)
- func (o *RequestOptions) SetHeaders(headers map[string]string)
- func (o *RequestOptions) SetOnRequestReady(onRequestReady OnRequestReadyHook)
- func (o *RequestOptions) SetOnResponseReady(onResponseReady OnResponseReadyHook)
- func (o *RequestOptions) SetStackTraceEnabled(enabled bool)
Constants ¶
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" HeaderAuthorization = "Authorization" HeaderCacheControl = "Cache-Control" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderHost = "Host" HeaderOrigin = "Origin" HeaderReferer = "Referer" HeaderUserAgent = "User-Agent" HeaderSetCookie = "Set-Cookie" HeaderLocation = "Location" HeaderETag = "ETag" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderXRequestedWith = "X-Requested-With" HeaderXForwardedFor = "X-Forwarded-For" HeaderXFrameOptions = "X-Frame-Options" HeaderStrictTransportSec = "Strict-Transport-Security" )
Variables ¶
This section is empty.
Functions ¶
func IsSuccessResponse ¶
Types ¶
type BodyMarshaler ¶
type BodyMarshaler interface { Marshal(body interface{}, writer io.Writer) error OnRequestReady(req *http.Request) error }
func NewJSONBodyMarshaler ¶
func NewJSONBodyMarshaler() BodyMarshaler
func NewNoopBodyMarshaler ¶
func NewNoopBodyMarshaler() BodyMarshaler
type BodyUnmarshaler ¶
type BodyUnmarshaler interface { Unmarshal(result interface{}, reader io.Reader) error OnRequestReady(req *http.Request) error }
func NewJSONBodyUnmarshaler ¶
func NewJSONBodyUnmarshaler() BodyUnmarshaler
type EnrichedError ¶
func (*EnrichedError) Error ¶
func (e *EnrichedError) Error() string
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient() *HttpClient
func (*HttpClient) Clone ¶
func (c *HttpClient) Clone() *HttpClient
func (*HttpClient) NewConnectRequest ¶
func (c *HttpClient) NewConnectRequest(ctx context.Context, path string) *Request
func (*HttpClient) NewDeleteRequest ¶
func (c *HttpClient) NewDeleteRequest(ctx context.Context, path string) *Request
func (*HttpClient) NewGetRequest ¶
func (c *HttpClient) NewGetRequest(ctx context.Context, path string) *Request
func (*HttpClient) NewHeadRequest ¶
func (c *HttpClient) NewHeadRequest(ctx context.Context, path string) *Request
func (*HttpClient) NewOptionsRequest ¶
func (c *HttpClient) NewOptionsRequest(ctx context.Context, path string) *Request
func (*HttpClient) NewPatchRequest ¶
func (c *HttpClient) NewPatchRequest(ctx context.Context, path string, body interface{}) *Request
func (*HttpClient) NewPostRequest ¶
func (c *HttpClient) NewPostRequest(ctx context.Context, path string, body interface{}) *Request
func (*HttpClient) NewPutRequest ¶
func (c *HttpClient) NewPutRequest(ctx context.Context, path string, body interface{}) *Request
func (*HttpClient) NewRequest ¶
func (c *HttpClient) NewRequest(ctx context.Context, method, path string, body interface{}) *Request
NewRequest creates a new Request with the specified method, path, and body. It is mostly used internally. For convenience, you can use the NewGetRequest, NewPostRequest, etc. methods to create requests with common HTTP methods.
func (*HttpClient) NewTraceRequest ¶
func (c *HttpClient) NewTraceRequest(ctx context.Context, path string) *Request
func (*HttpClient) SetBodyMarshaler ¶
func (c *HttpClient) SetBodyMarshaler(marshaler BodyMarshaler) *HttpClient
func (*HttpClient) SetBodyUnmarshaler ¶
func (c *HttpClient) SetBodyUnmarshaler(unmarshaler BodyUnmarshaler) *HttpClient
func (*HttpClient) SetDumpOnError ¶
func (c *HttpClient) SetDumpOnError() *HttpClient
func (*HttpClient) SetHeader ¶
func (c *HttpClient) SetHeader(key, value string) *HttpClient
func (*HttpClient) SetHeaders ¶
func (c *HttpClient) SetHeaders(headers map[string]string) *HttpClient
func (*HttpClient) SetOnRequestReady ¶
func (c *HttpClient) SetOnRequestReady(onRequestReady OnRequestReadyHook) *HttpClient
func (*HttpClient) SetOnResponseReady ¶
func (c *HttpClient) SetOnResponseReady(onResponseReady OnResponseReadyHook) *HttpClient
func (*HttpClient) SetStackTraceEnabled ¶
func (c *HttpClient) SetStackTraceEnabled(enabled bool) *HttpClient
func (*HttpClient) SetTimeout ¶
func (c *HttpClient) SetTimeout(timeout time.Duration) *HttpClient
type JSONBodyMarshaler ¶
type JSONBodyMarshaler struct{}
func (*JSONBodyMarshaler) Marshal ¶
func (m *JSONBodyMarshaler) Marshal(body interface{}, writer io.Writer) error
func (*JSONBodyMarshaler) OnRequestReady ¶
func (m *JSONBodyMarshaler) OnRequestReady(req *http.Request) error
type JSONBodyUnmarshaler ¶
type JSONBodyUnmarshaler struct{}
func (*JSONBodyUnmarshaler) OnRequestReady ¶
func (u *JSONBodyUnmarshaler) OnRequestReady(req *http.Request) error
type NoopBodyMarshaler ¶
type NoopBodyMarshaler struct{}
func (*NoopBodyMarshaler) Marshal ¶
func (m *NoopBodyMarshaler) Marshal(body interface{}, writer io.Writer) error
func (*NoopBodyMarshaler) OnRequestReady ¶
func (m *NoopBodyMarshaler) OnRequestReady(req *http.Request) error
type OnRequestReadyHook ¶
type OnResponseReadyHook ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) SetBodyMarshaler ¶
func (r *Request) SetBodyMarshaler(marshaler BodyMarshaler) *Request
SetBodyMarshaler sets the BodyMarshaler at the request level. Does not affect the client.
func (*Request) SetBodyUnmarshaler ¶
func (r *Request) SetBodyUnmarshaler(unmarshaler BodyUnmarshaler) *Request
SetBodyUnmarshaler sets the BodyUnmarshaler at the request level. Does not affect the client.
func (*Request) SetDumpOnError ¶
SetDumpOnError configures logging of the request, response and error when an error occurs. http.Request and http.Response bodies will be logged as well, if they are set. original, body passed by the caller code will be logged as well, if it is set. This method will also enable the StackTraceEnabled option, which will add a stack trace to the error if it occurs.
func (*Request) SetHeader ¶
SetHeader sets a single header for the request. This will override any headers set at the client level but only for this request.
func (*Request) SetHeaders ¶
SetHeaders sets the headers for the request. This will override any headers set at the client level but only for this request.
func (*Request) SetOnRequestReady ¶
func (r *Request) SetOnRequestReady(onRequestReady OnRequestReadyHook) *Request
SetOnRequestReady sets a hook that will be called right after an http.Request is created and all headers and body are set. This method will override any hooks set at the client level, without affecting the client, but only for this request.
func (*Request) SetOnResponseReady ¶
func (r *Request) SetOnResponseReady(onResponseReady OnResponseReadyHook) *Request
SetOnResponseReady sets a hook that will be called right after the response is received and before it is processed. This method will override any hooks set at the client level, without affecting the client, but only for this request.
func (*Request) SetStackTraceEnabled ¶
SetStackTraceEnabled enables or disables the stack trace in the error if it occurs.
func (*Request) WriteBodyTo ¶
WriteBodyTo sets the destination for unmarshalling the response body. This method will consume the response body and close it after reading. This is the recommended way to consume the response body as it prevents resource leaks, provides type safety and a unified way to work with body. In case this method in not used, the caller must close the response body manually after reading it to prevent resource leaks!
type RequestOptions ¶
type RequestOptions struct { BodyMarshaler BodyMarshaler BodyUnmarshaler BodyUnmarshaler Headers map[string]string OnRequestReady OnRequestReadyHook OnResponseReady OnResponseReadyHook OnErrorHooks []onErrorHook StackTraceEnabled bool }
func (*RequestOptions) Clone ¶
func (o *RequestOptions) Clone() *RequestOptions
func (*RequestOptions) SetBodyMarshaler ¶
func (o *RequestOptions) SetBodyMarshaler(marshaler BodyMarshaler)
func (*RequestOptions) SetBodyUnmarshaler ¶
func (o *RequestOptions) SetBodyUnmarshaler(unmarshaler BodyUnmarshaler)
func (*RequestOptions) SetDumpOnError ¶
func (o *RequestOptions) SetDumpOnError()
func (*RequestOptions) SetHeader ¶
func (o *RequestOptions) SetHeader(key, value string)
func (*RequestOptions) SetHeaders ¶
func (o *RequestOptions) SetHeaders(headers map[string]string)
func (*RequestOptions) SetOnRequestReady ¶
func (o *RequestOptions) SetOnRequestReady(onRequestReady OnRequestReadyHook)
func (*RequestOptions) SetOnResponseReady ¶
func (o *RequestOptions) SetOnResponseReady(onResponseReady OnResponseReadyHook)
func (*RequestOptions) SetStackTraceEnabled ¶
func (o *RequestOptions) SetStackTraceEnabled(enabled bool)