Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Delete(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Do(ctx context.Context, method, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Get(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Head(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Options(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Patch(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Post(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Put(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func (c *Client) Stream(ctx context.Context, method, target string, opts ...RequestOption) (*Stream, error)
- type ClientOption
- func WithAfterHook(fn func(context.Context, *Response, error) error) ClientOption
- func WithBaseURL(rawURL string) ClientOption
- func WithBeforeHook(fn func(context.Context, *http.Request) error) ClientOption
- func WithDefaultHeader(name, value string) ClientOption
- func WithDefaultHeaders(headers http.Header) ClientOption
- func WithDefaultQuery(name, value string) ClientOption
- func WithHTTPClient(client *http.Client) ClientOption
- func WithHook(hook Hook) ClientOption
- func WithMaxBodyBytes(n int64) ClientOption
- func WithProxy(proxyURL string) ClientOption
- func WithRetry(cfg RetryConfig) ClientOption
- func WithStatusValidator(fn StatusValidator) ClientOption
- func WithTLSConfig(tlsConfig *tls.Config) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransport(transport http.RoundTripper) ClientOption
- type DecodeError
- type Hook
- type HookFunc
- type MultipartPart
- type RequestError
- type RequestOption
- func WithBasicAuth(username, password string) RequestOption
- func WithBearerToken(token string) RequestOption
- func WithBody(contentType string, body io.Reader) RequestOption
- func WithBytes(contentType string, body []byte) RequestOption
- func WithDecodeJSON(v any) RequestOption
- func WithExpectedStatus(codes ...int) RequestOption
- func WithForm(values url.Values) RequestOption
- func WithFormMap(values map[string]string) RequestOption
- func WithHeader(name, value string) RequestOption
- func WithHeaders(headers http.Header) RequestOption
- func WithJSON(v any) RequestOption
- func WithMultipart(parts ...MultipartPart) RequestOption
- func WithQuery(name, value string) RequestOption
- func WithQueryValues(values url.Values) RequestOption
- func WithRequestHook(hook Hook) RequestOption
- func WithRequestMaxBodyBytes(n int64) RequestOption
- func WithRequestRetry(cfg RetryConfig) RequestOption
- func WithRequestStatusValidator(fn StatusValidator) RequestOption
- func WithRequestTimeout(timeout time.Duration) RequestOption
- func WithString(contentType, body string) RequestOption
- type Response
- func Delete(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func Do(ctx context.Context, method, target string, opts ...RequestOption) (*Response, error)
- func Get(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func Head(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func Options(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func Patch(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func Post(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- func Put(ctx context.Context, target string, opts ...RequestOption) (*Response, error)
- type RetryConfig
- type StatusError
- type StatusValidator
- type Stream
Constants ¶
View Source
const ( DefaultTimeout = 30 * time.Second DefaultMaxBodyBytes = 10 * 1024 * 1024 )
Variables ¶
View Source
var ( ErrNilContext = errors.New("request: nil context") ErrNilHTTPClient = errors.New("request: nil http client") ErrNilTransport = errors.New("request: nil transport") ErrNilBody = errors.New("request: nil body") ErrBodyAlreadySet = errors.New("request: body already set") ErrBodyNotReplayable = errors.New("request: body is not replayable") ErrBodyTooLarge = errors.New("request: response body too large") ErrNilMultipartPart = errors.New("request: multipart part has nil reader") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func DefaultClient ¶
func DefaultClient() *Client
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
type ClientOption ¶
type ClientOption func(*clientConfig) error
func WithAfterHook ¶
func WithBaseURL ¶
func WithBaseURL(rawURL string) ClientOption
func WithBeforeHook ¶
func WithDefaultHeader ¶
func WithDefaultHeader(name, value string) ClientOption
func WithDefaultHeaders ¶
func WithDefaultHeaders(headers http.Header) ClientOption
func WithDefaultQuery ¶
func WithDefaultQuery(name, value string) ClientOption
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
func WithHook ¶
func WithHook(hook Hook) ClientOption
func WithMaxBodyBytes ¶
func WithMaxBodyBytes(n int64) ClientOption
func WithProxy ¶
func WithProxy(proxyURL string) ClientOption
func WithRetry ¶
func WithRetry(cfg RetryConfig) ClientOption
func WithStatusValidator ¶
func WithStatusValidator(fn StatusValidator) ClientOption
func WithTLSConfig ¶
func WithTLSConfig(tlsConfig *tls.Config) ClientOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
func WithTransport ¶
func WithTransport(transport http.RoundTripper) ClientOption
type DecodeError ¶
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
func (*DecodeError) Unwrap ¶
func (e *DecodeError) Unwrap() error
type HookFunc ¶
type HookFunc struct {
Before func(ctx context.Context, req *http.Request) error
After func(ctx context.Context, resp *Response, err error) error
}
func (HookFunc) AfterResponse ¶
type MultipartPart ¶
type MultipartPart struct {
FieldName string
FileName string
ContentType string
Reader io.Reader
Headers textproto.MIMEHeader
}
func FieldPart ¶
func FieldPart(name, value string) MultipartPart
type RequestError ¶
func (*RequestError) Error ¶
func (e *RequestError) Error() string
func (*RequestError) Unwrap ¶
func (e *RequestError) Unwrap() error
type RequestOption ¶
type RequestOption func(*requestConfig) error
func WithBasicAuth ¶
func WithBasicAuth(username, password string) RequestOption
func WithBearerToken ¶
func WithBearerToken(token string) RequestOption
func WithBytes ¶
func WithBytes(contentType string, body []byte) RequestOption
func WithDecodeJSON ¶
func WithDecodeJSON(v any) RequestOption
func WithExpectedStatus ¶
func WithExpectedStatus(codes ...int) RequestOption
func WithForm ¶
func WithForm(values url.Values) RequestOption
func WithFormMap ¶
func WithFormMap(values map[string]string) RequestOption
func WithHeader ¶
func WithHeader(name, value string) RequestOption
func WithHeaders ¶
func WithHeaders(headers http.Header) RequestOption
func WithJSON ¶
func WithJSON(v any) RequestOption
func WithMultipart ¶
func WithMultipart(parts ...MultipartPart) RequestOption
func WithQuery ¶
func WithQuery(name, value string) RequestOption
func WithQueryValues ¶
func WithQueryValues(values url.Values) RequestOption
func WithRequestHook ¶
func WithRequestHook(hook Hook) RequestOption
func WithRequestMaxBodyBytes ¶
func WithRequestMaxBodyBytes(n int64) RequestOption
func WithRequestRetry ¶
func WithRequestRetry(cfg RetryConfig) RequestOption
func WithRequestStatusValidator ¶
func WithRequestStatusValidator(fn StatusValidator) RequestOption
func WithRequestTimeout ¶
func WithRequestTimeout(timeout time.Duration) RequestOption
func WithString ¶
func WithString(contentType, body string) RequestOption
type Response ¶
type Response struct {
Request *http.Request
Raw *http.Response
StatusCode int
Status string
Header http.Header
Body []byte
}
func (*Response) DecodeJSON ¶
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
WaitMin time.Duration
WaitMax time.Duration
Methods []string
StatusCodes []int
RetryErrors bool
ShouldRetry func(ctx context.Context, attempt int, resp *Response, err error) bool
}
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
type StatusError ¶
type StatusError struct {
Response *Response
}
func (*StatusError) Body ¶
func (e *StatusError) Body() []byte
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Header ¶
func (e *StatusError) Header() http.Header
func (*StatusError) StatusCode ¶
func (e *StatusError) StatusCode() int
type StatusValidator ¶
Click to show internal directories.
Click to hide internal directories.