Documentation ¶
Index ¶
- Variables
- func DefaultErrorMapper(ctx context.Context, resp *http.Response, body io.ReadCloser) error
- func DefaultErrorRetriable(ctx context.Context, err error) bool
- type ApiClient
- type ClientConfig
- type DoOption
- func WithRequestData(body any) DoOption
- func WithRequestHeader(k, v string) DoOption
- func WithRequestHeaders(headers map[string]string) DoOption
- func WithRequestVisitor(visitor func(r *http.Request) error) DoOption
- func WithResponseHeader(key string, value *string) DoOption
- func WithResponseUnmarshal(response any) DoOption
- func WithTokenSource(ts oauth2.TokenSource) DoOption
- type HttpError
- type RequestVisitor
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = NewApiClient(ClientConfig{ ErrorRetriable: DefaultErrorRetriable, ErrorMapper: DefaultErrorMapper, HTTPTimeout: 30 * time.Second, RetryTimeout: 5 * time.Minute, RateLimitPerSecond: 30, })
Functions ¶
func DefaultErrorMapper ¶
Types ¶
type ApiClient ¶
type ApiClient struct {
// contains filtered or unexported fields
}
func NewApiClient ¶
func NewApiClient(cfg ClientConfig) *ApiClient
func (*ApiClient) InContextForOAuth2 ¶
InContextForOAuth2 returns a context with a custom *http.Client to be used for only for token acquisition through golang.org/x/oauth2 package
type ClientConfig ¶
type ClientConfig struct { Visitors []RequestVisitor RetryTimeout time.Duration HTTPTimeout time.Duration InsecureSkipVerify bool DebugHeaders bool DebugTruncateBytes int RateLimitPerSecond int ErrorMapper func(ctx context.Context, resp *http.Response, body io.ReadCloser) error ErrorRetriable func(ctx context.Context, err error) bool TransientErrors []string Transport http.RoundTripper }
type DoOption ¶
type DoOption struct {
// contains filtered or unexported fields
}
func WithRequestData ¶
WithRequestData takes either a struct instance, map, string, bytes, or io.Reader and sends it either as query string for GET and DELETE calls, or as request body for POST, PUT, and PATCH calls.
Experimental: this method may eventually be split into more granular options.
func WithRequestHeader ¶
WithRequestHeader adds a request visitor, that sets a header on a request
func WithRequestHeaders ¶
WithRequestHeaders adds a request visitor, that set all headers from a map
func WithRequestVisitor ¶
WithRequestVisitor applies given function on a request
func WithResponseHeader ¶
func WithResponseUnmarshal ¶
func WithTokenSource ¶
func WithTokenSource(ts oauth2.TokenSource) DoOption
WithTokenSource uses the specified golang.org/x/oauth2 token source on a request