Documentation ¶
Index ¶
- Variables
- func NoRetries() (RetryCondition, Retryer)
- type BasicAuth
- type Client
- func (c *Client) Delete(url string) *RequestBuilder
- func (c *Client) Get(url string) *RequestBuilder
- func (c *Client) GlobalRequestConfig() *GlobalRequestConfig
- func (c *Client) Patch(url string) *RequestBuilder
- func (c *Client) Post(url string) *RequestBuilder
- func (c *Client) Put(url string) *RequestBuilder
- type ErrorResponse
- type GlobalRequestConfig
- type Middleware
- type MultipartData
- type MultipartFieldFile
- type Option
- type Request
- type RequestBodyWriter
- type RequestBuilder
- func (b *RequestBuilder) BasicAuth(ba BasicAuth) *RequestBuilder
- func (b *RequestBuilder) Cookie(cookie *http.Cookie) *RequestBuilder
- func (b *RequestBuilder) Do(ctx context.Context) (*Response, error)
- func (b *RequestBuilder) DoAndReadBody(ctx context.Context) ([]byte, int, error)
- func (b *RequestBuilder) DoWithoutResponse(ctx context.Context) error
- func (b *RequestBuilder) FormDataRequestBody(data map[string][]string) *RequestBuilder
- func (b *RequestBuilder) Header(name string, value string) *RequestBuilder
- func (b *RequestBuilder) JsonRequestBody(value any) *RequestBuilder
- func (b *RequestBuilder) JsonResponseBody(responsePtr any) *RequestBuilder
- func (b *RequestBuilder) MultipartRequestBody(data *MultipartData) *RequestBuilder
- func (b *RequestBuilder) QueryParams(queryParams map[string]any) *RequestBuilder
- func (b *RequestBuilder) RequestBody(body []byte) *RequestBuilder
- func (b *RequestBuilder) Retry(cond RetryCondition, retryer Retryer) *RequestBuilder
- func (b *RequestBuilder) StatusCodeToError() *RequestBuilder
- func (b *RequestBuilder) Timeout(timeout time.Duration) *RequestBuilder
- type Response
- type ResponseBodyReader
- type RetryCondition
- type Retryer
- type RoundTripper
- type RoundTripperFunc
Constants ¶
This section is empty.
Variables ¶
var ( StdClient = &http.Client{ Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: defaultTransportDialContext(&net.Dialer{ Timeout: 3 * time.Second, KeepAlive: 30 * time.Second, }), ForceAttemptHTTP2: true, MaxIdleConns: 512, MaxIdleConnsPerHost: 32, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 5 * time.Second, ExpectContinueTimeout: 1 * time.Second, ReadBufferSize: 8 * 1024, WriteBufferSize: 8 * 1024, }, } )
Functions ¶
func NoRetries ¶
func NoRetries() (RetryCondition, Retryer)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Delete ¶
func (c *Client) Delete(url string) *RequestBuilder
func (*Client) Get ¶
func (c *Client) Get(url string) *RequestBuilder
func (*Client) GlobalRequestConfig ¶
func (c *Client) GlobalRequestConfig() *GlobalRequestConfig
func (*Client) Patch ¶
func (c *Client) Patch(url string) *RequestBuilder
func (*Client) Post ¶
func (c *Client) Post(url string) *RequestBuilder
func (*Client) Put ¶
func (c *Client) Put(url string) *RequestBuilder
type ErrorResponse ¶
func (ErrorResponse) Error ¶
func (e ErrorResponse) Error() string
type GlobalRequestConfig ¶
type GlobalRequestConfig struct { Timeout time.Duration BaseUrl string BasicAuth *BasicAuth Cookies []*http.Cookie Headers map[string]string }
func NewGlobalRequestConfig ¶
func NewGlobalRequestConfig() *GlobalRequestConfig
type Middleware ¶
type Middleware func(next RoundTripper) RoundTripper
type MultipartData ¶
type MultipartData struct { Files map[string]MultipartFieldFile Values map[string]string }
type MultipartFieldFile ¶
type MultipartFieldFile struct { Filename string Reader io.ReadCloser }
type Option ¶
type Option func(c *Client)
func WithMiddlewares ¶
func WithMiddlewares(mws ...Middleware) Option
type RequestBodyWriter ¶
type RequestBuilder ¶
type RequestBuilder struct {
// contains filtered or unexported fields
}
func NewRequestBuilder ¶
func NewRequestBuilder(method string, url string, cfg *GlobalRequestConfig, execute func(ctx context.Context, req *RequestBuilder) (*Response, error)) *RequestBuilder
func (*RequestBuilder) BasicAuth ¶
func (b *RequestBuilder) BasicAuth(ba BasicAuth) *RequestBuilder
func (*RequestBuilder) Cookie ¶
func (b *RequestBuilder) Cookie(cookie *http.Cookie) *RequestBuilder
func (*RequestBuilder) DoAndReadBody ¶
func (*RequestBuilder) DoWithoutResponse ¶
func (b *RequestBuilder) DoWithoutResponse(ctx context.Context) error
func (*RequestBuilder) FormDataRequestBody ¶
func (b *RequestBuilder) FormDataRequestBody(data map[string][]string) *RequestBuilder
func (*RequestBuilder) Header ¶
func (b *RequestBuilder) Header(name string, value string) *RequestBuilder
func (*RequestBuilder) JsonRequestBody ¶
func (b *RequestBuilder) JsonRequestBody(value any) *RequestBuilder
func (*RequestBuilder) JsonResponseBody ¶
func (b *RequestBuilder) JsonResponseBody(responsePtr any) *RequestBuilder
JsonResponseBody If response status code between 200 and 299, unmarshal response body to responsePtr
func (*RequestBuilder) MultipartRequestBody ¶
func (b *RequestBuilder) MultipartRequestBody(data *MultipartData) *RequestBuilder
MultipartRequestBody Useful function to transfer "big" files because it does not load files into memory Does not support Request.Body in middlewares and ignores Retry
func (*RequestBuilder) QueryParams ¶
func (b *RequestBuilder) QueryParams(queryParams map[string]any) *RequestBuilder
func (*RequestBuilder) RequestBody ¶
func (b *RequestBuilder) RequestBody(body []byte) *RequestBuilder
func (*RequestBuilder) Retry ¶
func (b *RequestBuilder) Retry(cond RetryCondition, retryer Retryer) *RequestBuilder
func (*RequestBuilder) StatusCodeToError ¶
func (b *RequestBuilder) StatusCodeToError() *RequestBuilder
StatusCodeToError If set and Response.IsSuccess is false, Do return ErrorResponse as error
func (*RequestBuilder) Timeout ¶
func (b *RequestBuilder) Timeout(timeout time.Duration) *RequestBuilder
Timeout Set per request attempt timeout, default timeout 15 seconds
type Response ¶
func (*Response) Body ¶
Body Read and return full response body Be careful, after calling Close returned data is no longer available Do not call close or copy slice if you want to use data outside the calling function
func (*Response) BodyCopy ¶
BodyCopy Return copy of response body Slice is available after calling Close
func (*Response) Close ¶
func (r *Response) Close()
Close Release all resources associated with Response (buffer, tcp connection, context) After call, bytes slice returned by Body can not be used
func (*Response) StatusCode ¶
type ResponseBodyReader ¶
type RetryCondition ¶
func IfErrorOr5XXStatus ¶
func IfErrorOr5XXStatus() RetryCondition