Documentation ¶
Index ¶
- Constants
- func DefaultErrorMapper(ctx context.Context, resp common.ResponseWrapper) error
- func DefaultErrorRetriable(ctx context.Context, err error) bool
- func EncodeMultiSegmentPathParameter(p string) string
- type ApiClient
- func (c *ApiClient) Do(ctx context.Context, method, path string, opts ...DoOption) error
- func (c *ApiClient) GetOAuthToken(ctx context.Context, authDetails string, token *oauth2.Token) (*oauth2.Token, error)
- func (c *ApiClient) InContextForOAuth2(ctx context.Context) context.Context
- func (c *ApiClient) RoundTrip(request *http.Request) (*http.Response, error)
- 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 WithToken(token *oauth2.Token) DoOption
- func WithTokenSource(ts oauth2.TokenSource) DoOption
- func WithUrlEncodedData(body any) DoOption
- type GetOAuthTokenRequest
- type HttpError
- type RequestVisitor
- type TimeoutTicker
Constants ¶
const JWTGrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer"
const UrlEncodedContentType = "application/x-www-form-urlencoded"
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorMapper ¶
func DefaultErrorMapper(ctx context.Context, resp common.ResponseWrapper) error
DefaultErrorMapper returns *HttpError
func EncodeMultiSegmentPathParameter ¶ added in v0.37.0
Types ¶
type ApiClient ¶
type ApiClient struct {
// contains filtered or unexported fields
}
func NewApiClient ¶
func NewApiClient(cfg ClientConfig) *ApiClient
func (*ApiClient) GetOAuthToken ¶ added in v0.41.0
func (c *ApiClient) GetOAuthToken(ctx context.Context, authDetails string, token *oauth2.Token) (*oauth2.Token, error)
Returns a new OAuth token using the provided token. The token must be a JWT token. The resulting token is scoped to the authorization details provided.
**NOTE:** Experimental: This API may change or be removed in a future release without warning.
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 { AuthVisitor RequestVisitor Visitors []RequestVisitor RetryTimeout time.Duration HTTPTimeout time.Duration InsecureSkipVerify bool DebugHeaders bool DebugTruncateBytes int RateLimitPerSecond int ErrorMapper func(ctx context.Context, resp common.ResponseWrapper) 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 ¶
WithResponseUnmarshal unmarshals the response body into response. The supported response types are the following:
- *bytes.Buffer,
- *io.ReadCloser,
- *[]byte,
- a pointer to a struct with a Contents io.ReadCloser field,
- a pointer to a struct representing a JSON object.
If response is a pointer to a io.ReadCloser or a struct with a io.ReadCloser field name "Contents", then the response io.ReadCloser is set to the value of the body's reader without actually reading it.
func WithToken ¶ added in v0.43.1
WithToken uses the specified golang.org/x/oauth2 token on a request
func WithTokenSource ¶
func WithTokenSource(ts oauth2.TokenSource) DoOption
WithTokenSource uses the specified golang.org/x/oauth2 token source on a request
func WithUrlEncodedData ¶ added in v0.41.0
WithUrlEncodedData takes either a struct instance, map, string, bytes, or io.Reader plus a content type, and sends it either as query string for GET and DELETE calls, or as request body for POST, PUT, and PATCH calls. The content type is set to "application/x-www-form-urlencoded" and the body is encoded as a query string.
Experimental: this method may eventually be split into more granular options.
type GetOAuthTokenRequest ¶ added in v0.41.0
type GetOAuthTokenRequest struct { // Defines the method used to get the token. GrantType string `url:"grant_type"` // An array of authorization details that the token should be scoped to. This needs to be passed in string format. AuthorizationDetails string `url:"authorization_details"` // The token that will be exchanged for an OAuth token. Assertion string `url:"assertion"` }
GetOAuthTokenRequest is the request to get an OAuth token. It follows the OAuth 2.0 Rich Authorization Requests specification. https://datatracker.ietf.org/doc/html/rfc9396
type RequestVisitor ¶
type TimeoutTicker ¶ added in v0.34.0
type TimeoutTicker interface { Tick() Cancel() }