Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteJSON[T any](ctx context.Context, c *Client, path string, opts ...RequestOption) (T, error)
- func DoJSON[T any](ctx context.Context, c *Client, method, path string, body any, ...) (T, error)
- func GetJSON[T any](ctx context.Context, c *Client, path string, opts ...RequestOption) (T, error)
- func PatchJSON[T any](ctx context.Context, c *Client, path string, body any, opts ...RequestOption) (T, error)
- func PostJSON[T any](ctx context.Context, c *Client, path string, body any, opts ...RequestOption) (T, error)
- func PutJSON[T any](ctx context.Context, c *Client, path string, body any, opts ...RequestOption) (T, error)
- type AuthConfig
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Delete(ctx context.Context, path string, response any, opts ...RequestOption) error
- func (c *Client) Do(ctx context.Context, method string, path string, body any, response any, ...) error
- func (c *Client) Get(ctx context.Context, path string, response any, opts ...RequestOption) error
- func (c *Client) Head(ctx context.Context, path string, opts ...RequestOption) (*Response, error)
- func (c *Client) Options(ctx context.Context, path string, opts ...RequestOption) (*Response, error)
- func (c *Client) Patch(ctx context.Context, path string, body any, response any, ...) error
- func (c *Client) Post(ctx context.Context, path string, body any, response any, ...) error
- func (c *Client) Put(ctx context.Context, path string, body any, response any, ...) error
- type Doer
- type ErrorResponse
- type Option
- func WithAuth(cfg AuthConfig) Option
- func WithDefaultHeaders(headers map[string]string) Option
- func WithHTTPClient(httpClient *http.Client) Option
- func WithMaxResponseSize(size int64) Option
- func WithRequestIDKey(key any) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTokenProvider(provider TokenProvider) Option
- type Registry
- func (r *Registry) Client(name string) *Client
- func (r *Registry) Count() int
- func (r *Registry) GetClient(name string) (*Client, bool)
- func (r *Registry) Has(name string) bool
- func (r *Registry) MustClient(name string) *Client
- func (r *Registry) Names() []string
- func (r *Registry) Register(name, baseURL string, opts ...Option) *Registry
- func (r *Registry) Unregister(name string) bool
- type RequestOption
- type Response
- type ServiceError
- type TokenProvider
Constants ¶
View Source
const ( DefaultTimeout = 30 * time.Second HeaderContentType = "Content-Type" HeaderXRequestID = "X-Request-ID" HeaderAuthorization = "Authorization" ContentTypeJSON = "application/json" ContentTypeFormURLEncoded = "application/x-www-form-urlencoded" )
Variables ¶
View Source
var ( ErrRequestFailed = errors.New("httpclient: request failed") ErrServiceError = errors.New("httpclient: service error") ErrDecodeResponse = errors.New("httpclient: failed to decode response") ErrCreateRequest = errors.New("httpclient: failed to create request") ErrEncodeBody = errors.New("httpclient: failed to encode request body") ErrAuthFailed = errors.New("httpclient: authentication failed") ErrResponseTooLarge = errors.New("httpclient: response body too large") )
Functions ¶
func DeleteJSON ¶
Types ¶
type AuthConfig ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
type ErrorResponse ¶
type Option ¶
type Option func(*Client)
func WithAuth ¶
func WithAuth(cfg AuthConfig) Option
func WithDefaultHeaders ¶
func WithHTTPClient ¶
func WithMaxResponseSize ¶
func WithRequestIDKey ¶
func WithTimeout ¶
func WithTokenProvider ¶
func WithTokenProvider(provider TokenProvider) Option
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func (*Registry) MustClient ¶
func (*Registry) Unregister ¶
type RequestOption ¶
type RequestOption func(*requestConfig)
func WithQuery ¶
func WithQuery(key, value string) RequestOption
func WithQueryParams ¶
func WithQueryParams(params map[string]string) RequestOption
func WithRequestHeader ¶
func WithRequestHeader(key, value string) RequestOption
func WithRequestID ¶
func WithRequestID(requestID string) RequestOption
func WithRequestTimeout ¶
func WithRequestTimeout(timeout time.Duration) RequestOption
type ServiceError ¶
func IsServiceError ¶
func IsServiceError(err error) (*ServiceError, bool)
func NewServiceError ¶
func NewServiceError(statusCode int, message, internal, requestID string) *ServiceError
func (*ServiceError) Error ¶
func (e *ServiceError) Error() string
func (*ServiceError) Is ¶
func (e *ServiceError) Is(target error) bool
func (*ServiceError) Unwrap ¶
func (e *ServiceError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.