Documentation
¶
Index ¶
- Constants
- Variables
- func Queries[T Query](values ...T) []string
- func WithForceAttemptHTTP2(forceAttemptHTTP2 bool) func(*client)
- func WithIdleConnectionTimeout(idleConnectionTimeout time.Duration) func(*client)
- func WithInterceptors(interceptors ...Interceptor) func(*client)
- func WithMaxConnectionsPerHost(maxConnectionsPerHost int) func(*client)
- func WithMaxIdleConnections(maxIdleConnections int) func(*client)
- func WithMaxIdleConnectionsPerHost(maxIdleConnectionsPerHost int) func(*client)
- func WithTimeout(timeout time.Duration) func(*client)
- type Client
- type Decoder
- type Interceptor
- type Query
- type Request
- type Response
- type RoundTripper
Constants ¶
const ( DefaultTimeout = 30 * time.Second DefaultIdleConnectionTimeout = 90 * time.Second DefaultMaxIdleConnections = 100 DefaultMaxConnectionsPerHost = 15 DefaultMaxIdleConnectionsPerHost = 10 DefaultForceAttemptHTTP2 = true )
const ( ContentType = "Content-Type" ApplicationJSON = "application/json" ApplicationXML = "application/xml" ApplicationFormUrlencoded = "application/x-www-form-urlencoded" MultipartFormData = "multipart/form-data" Authorization = "Authorization" Basic = "Basic" Bearer = "Bearer" JWT = "JWT" )
Variables ¶
var (
ErrNoBody = errors.New("no body")
)
Functions ¶
func WithForceAttemptHTTP2 ¶
func WithForceAttemptHTTP2(forceAttemptHTTP2 bool) func(*client)
WithForceAttemptHTTP2 controls whether HTTP/2 is enabled when a non-zero Dial, DialTLS, or DialContext func or TLSClientConfig is provided. By default, use of any those fields conservatively disables HTTP/2. To use a custom dialer or TLS config and still attempt HTTP/2 upgrades, set this to true. If not provided, DefaultForceAttemptHTTP2 is used.
func WithIdleConnectionTimeout ¶
WithIdleConnectionTimeout controls amount of time an idle (keep-alive) connection will remain idle before closing itself. If not provided, DefaultIdleConnectionTimeout is used.
func WithInterceptors ¶
func WithInterceptors(interceptors ...Interceptor) func(*client)
WithInterceptors wraps Client with given interceptors
func WithMaxConnectionsPerHost ¶
func WithMaxConnectionsPerHost(maxConnectionsPerHost int) func(*client)
WithMaxConnectionsPerHost optionally limits the total number of connections per host, including connections in the dialing, active, and idle states. On limit violation, dials will block. If not provided, DefaultMaxConnectionsPerHost is used.
func WithMaxIdleConnections ¶
func WithMaxIdleConnections(maxIdleConnections int) func(*client)
WithMaxIdleConnections controls the maximum number of idle (keep-alive) connections across all hosts. If not provided, DefaultMaxIdleConnections is used.
func WithMaxIdleConnectionsPerHost ¶
func WithMaxIdleConnectionsPerHost(maxIdleConnectionsPerHost int) func(*client)
WithMaxIdleConnectionsPerHost controls the maximum idle (keep-alive) connections to keep per-host. If not provided, DefaultMaxIdleConnectionsPerHost is used.
func WithTimeout ¶
WithTimeout sets timeout for all client requests. Timeout implemented without using http.Client's Timeout property, but with context. Client timeout has lesser priority than Request timeout property. If not provided, DefaultTimeout is used.
Types ¶
type Interceptor ¶
type Interceptor func(http.RoundTripper) http.RoundTripper
func Retry ¶
func Retry(statusCodes ...int) Interceptor
Retry interceptor retry request on request failure or on defined Response status codes. By default Retry uses defaultStatusCodes
type Request ¶
type Request interface {
Get(
ctx context.Context,
url string,
) (resp *Response, err error)
Head(
ctx context.Context,
url string,
) (resp *Response, err error)
Post(
ctx context.Context,
url string,
body io.Reader,
) (resp *Response, err error)
Put(
ctx context.Context,
url string,
body io.Reader,
) (resp *Response, err error)
Delete(
ctx context.Context,
url string,
) (resp *Response, err error)
Connect(
ctx context.Context,
url string,
) (resp *Response, err error)
Options(
ctx context.Context,
url string,
) (resp *Response, err error)
Trace(
ctx context.Context,
url string,
) (resp *Response, err error)
Patch(
ctx context.Context,
url string,
) (resp *Response, err error)
URL() *url.URL
Header() http.Header
Body() (io.Reader, error)
WithHeader(
key string,
values ...string,
) Request
WithHeaders(
values map[string][]string,
) Request
WithContentType(
value string,
) Request
WithJSONContentType() Request
WithXMLContentType() Request
WithMultipartFormContentType() Request
WithFormContentType() Request
WithAuth(
values ...string,
) Request
WithBasicAuth(
username,
password string,
) Request
WithBearerAuth(
value string,
) Request
WithJWTAuth(
value string,
) Request
WithQuery(
name string,
values ...string,
) Request
WithQueries(
values map[string][]string,
) Request
WithTimeout(
timeout time.Duration,
) Request
}
type Response ¶
func (*Response) JSONDecoder ¶
JSONDecoder returns JSON decoder.
func (*Response) XMLDecoder ¶
XMLDecoder returns XML decoder.