Documentation
¶
Index ¶
- Constants
- Variables
- func Delete(cxt context.Context, u string, input, output interface{}) (*http.Response, error)
- func Get(cxt context.Context, u string, entity interface{}) (*http.Response, error)
- func Marshal(ctype string, entity interface{}) (io.Reader, error)
- func Post(cxt context.Context, u string, input, output interface{}) (*http.Response, error)
- func Put(cxt context.Context, u string, input, output interface{}) (*http.Response, error)
- func URLWithParams(s string, params interface{}) (string, error)
- func Unmarshal(rsp *http.Response, entity interface{}) error
- type Authorizer
- type BasicAuthorizer
- type BearerAuthorizer
- type Client
- func (c *Client) Authorizer() Authorizer
- func (c *Client) Base() *url.URL
- func (c *Client) Delete(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) Exec(req *http.Request, entity interface{}, opts ...Option) (*http.Response, error)
- func (c *Client) Get(cxt context.Context, u string, output interface{}, opts ...Option) (*http.Response, error)
- func (c *Client) Log() *slog.Logger
- func (c *Client) Observers() *events.Observers
- func (c *Client) Patch(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
- func (c *Client) Post(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
- func (c *Client) Put(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
- func (c *Client) RoundTrip(req *http.Request) (*http.Response, error)
- func (c *Client) WithAuthorizer(a Authorizer) *Client
- func (c *Client) WithBase(b *url.URL) *Client
- func (c *Client) WithObservers(o *events.Observers) *Client
- type Config
- type Debug
- type Entity
- type EntityMarshaler
- type EntityUnmarshaler
- type Error
- func (e *Error) Error() string
- func (e *Error) Redacted() error
- func (e *Error) SetCause(err error) *Error
- func (e *Error) SetEntity(ent *Entity) *Error
- func (e *Error) SetEntityFromResponse(rsp *http.Response) *Error
- func (e *Error) SetId(id int64) *Error
- func (e *Error) SetRequest(req *http.Request) *Error
- func (e *Error) Unwrap() error
- type HeaderAuthorizer
- type OAuthAuthorizer
- type Option
- func WithAuthorizer(auth Authorizer) Option
- func WithBaseURL(base string) Option
- func WithDebug(on bool) Option
- func WithHeader(key, val string) Option
- func WithHeaders(hdr http.Header) Option
- func WithLogger(log *slog.Logger) Option
- func WithName(name string) Option
- func WithObservers(obs ...interface{}) Option
- func WithRateLimiter(l ratelimit.Limiter) Option
- func WithRetryDelay(d time.Duration) Option
- func WithRetryStatus(s ...int) Option
- type QueryAuthorizer
Constants ¶
View Source
const ( JSON = "application/json" URLEncoded = "application/x-www-form-urlencoded" Multipart = "multipart/form-data" PlainText = "text/plain" )
Variables ¶
View Source
var ( ErrUnsupportedMimetype = errors.New("Unsupported content type") ErrUnsupportedContentEncoding = errors.New("Unsupported content encoding") ErrUnexpectedStatusCode = errors.New("Unexpected status code") ErrCouldNotAuthorize = errors.New("Could not authorize request") ErrCouldNotUnmarshalResponse = errors.New("Could not unmarshal response") )
View Source
var ( ErrNotFound = errors.New("Not found") ErrBadRequest = errors.New("Bad request") ErrForbidden = errors.New("Forbidden") ErrUnprocessableEntity = errors.New("Unprocessable entity") ErrInternalServerError = errors.New("Internal server error") )
Sentinal errors are wrapped to provide a simpler test for common conditions that are related to response status codes.
View Source
var RecoverableStatuses = []int{ http.StatusInternalServerError, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout, }
Functions ¶
func URLWithParams ¶
Types ¶
type Authorizer ¶
An authorizer authorizes requests
type BasicAuthorizer ¶
type BasicAuthorizer struct {
// contains filtered or unexported fields
}
func NewBasicAuthorizer ¶
func NewBasicAuthorizer(u, p string) BasicAuthorizer
type BearerAuthorizer ¶
type BearerAuthorizer struct {
// contains filtered or unexported fields
}
func NewBearerAuthorizer ¶
func NewBearerAuthorizer(t string) BearerAuthorizer
type Client ¶
An API client
func NewWithConfig ¶
Create a new client with a configuration
func (*Client) Authorizer ¶
func (c *Client) Authorizer() Authorizer
func (*Client) Delete ¶
func (c *Client) Delete(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
A convenience for Exec with a DELETE request
func (*Client) Exec ¶
func (c *Client) Exec(req *http.Request, entity interface{}, opts ...Option) (*http.Response, error)
Perform a request and attempt to unmarshal the response into an entity.
func (*Client) Get ¶
func (c *Client) Get(cxt context.Context, u string, output interface{}, opts ...Option) (*http.Response, error)
A convenience for Exec with a GET request
func (*Client) Patch ¶
func (c *Client) Patch(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
A convenience for Exec with a PATCH request. This is the same as PUT and it is included for the benefit of those misguided APIs that use PATCH operations.
func (*Client) Post ¶
func (c *Client) Post(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
A convenience for Exec with a POST request
func (*Client) Put ¶
func (c *Client) Put(cxt context.Context, u string, input, output interface{}, opts ...Option) (*http.Response, error)
A convenience for Exec with a PUT request
func (*Client) WithAuthorizer ¶
func (c *Client) WithAuthorizer(a Authorizer) *Client
type Config ¶
type Config struct {
Name string
BaseURL string
Timeout time.Duration
Client *http.Client
Authorizer Authorizer
Observers *events.Observers
RateLimiter ratelimit.Limiter
RetryStatus []int
RetryDelay time.Duration
Header http.Header
ContentType string
Logger *slog.Logger
Verbose bool
Debug bool
}
Client configuration
func (Config) WithOptions ¶
type EntityMarshaler ¶
type EntityUnmarshaler ¶
type Error ¶
type Error struct {
ReqId int64
Status int
Method string
URL string
Entity *Entity
Message string
Cause error
}
func (*Error) SetEntityFromResponse ¶
type HeaderAuthorizer ¶
type HeaderAuthorizer struct {
// contains filtered or unexported fields
}
func NewHeaderAuthorizer ¶
func NewHeaderAuthorizer(h http.Header) HeaderAuthorizer
type OAuthAuthorizer ¶
type OAuthAuthorizer struct {
// contains filtered or unexported fields
}
func NewOAuthAuthorizer ¶
func NewOAuthAuthorizer(src oauth2.TokenSource) OAuthAuthorizer
type Option ¶
func WithAuthorizer ¶
func WithAuthorizer(auth Authorizer) Option
func WithBaseURL ¶
func WithHeader ¶
func WithHeaders ¶
func WithLogger ¶ added in v0.6.0
func WithObservers ¶
func WithObservers(obs ...interface{}) Option
func WithRateLimiter ¶
func WithRetryDelay ¶
func WithRetryStatus ¶
type QueryAuthorizer ¶
func NewQueryAuthorizer ¶
func NewQueryAuthorizer(params url.Values) QueryAuthorizer
Click to show internal directories.
Click to hide internal directories.