Documentation
¶
Index ¶
- type Client
- func (c *Client) Delete(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
- func (c *Client) Patch(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
- func (c *Client) Post(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
- func (c *Client) Put(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
- func (c *Client) SendRequest(ctx context.Context, method string, path string, options ...RequestOption) (resp *http.Response, err error)
- type ClientOption
- type HandleFunc
- type Interceptor
- type Observer
- type ObserverOption
- type Option
- func Header(key, value string) Option
- func Inspect() Option
- func Intercept(i Interceptor) Option
- func RequestBody(contentType string, bodyFunc func() (io.Reader, error)) Option
- func RequestBodyBytes(contentType string, body []byte) Option
- func RequestBodyForm(data url.Values) Option
- func RequestBodyJSON(body any) Option
- func RequestBodyStream(contentType string, body io.Reader) Option
- func RequestBodyString(body string) Option
- func ResponseBody(handler responseBodyHandler) Option
- func ResponseBodyBytes(dest *[]byte) Option
- func ResponseBodyJSON(successBody any, errBody any) Option
- func ResponseBodyString(dest *string) Option
- type RequestOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(options ...ClientOption) *Client
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
Delete sends a DELETE request to the specified URL.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
Get sends a GET request to the specified URL.
func (*Client) Patch ¶ added in v1.2.0
func (c *Client) Patch(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
Patch sends a PATCH request to the specified URL.
func (*Client) Post ¶
func (c *Client) Post(ctx context.Context, url string, options ...RequestOption) (*http.Response, error)
Post sends a POST request to the specified URL.
type ClientOption ¶
type ClientOption interface {
Client(*Client)
}
func BaseURL ¶
func BaseURL(baseURL string) ClientOption
func HTTPClient ¶
func HTTPClient(h http.Client) ClientOption
func Timeout ¶
func Timeout(timeout time.Duration) ClientOption
type HandleFunc ¶
type HandleFunc func(ctx context.Context, req *http.Request, next Interceptor) (*http.Response, error)
func Inspector ¶
func Inspector() HandleFunc
Inspector is an interceptor that logs the request and response to stdout.
type Interceptor ¶
type Interceptor interface {
Handle(ctx context.Context, req *http.Request, next Interceptor) (*http.Response, error)
}
func Chain ¶
func Chain(interceptors ...Interceptor) Interceptor
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
func NewObserver ¶
func NewObserver(opts ...ObserverOption) (*Observer, error)
type ObserverOption ¶
type ObserverOption func(*Observer)
func WithMetricPrefix ¶
func WithMetricPrefix(prefix string) ObserverOption
type Option ¶
type Option interface {
ClientOption
RequestOption
}
func Intercept ¶
func Intercept(i Interceptor) Option
func RequestBodyBytes ¶
RequestBodyBytes sets the content type to application/octet-stream.
func RequestBodyForm ¶
RequestBodyForm sets the content type to application/x-www-form-urlencoded.
func RequestBodyJSON ¶
RequestBodyJSON json marshals whatever is passed in and sets the content type to application/json.
func RequestBodyStream ¶
RequestBodyStream sets the content type to the provided value. good for when you have a stream of data.
func RequestBodyString ¶
RequestBodyString sets the content type to text/plain.
func ResponseBody ¶
func ResponseBody(handler responseBodyHandler) Option
func ResponseBodyBytes ¶
func ResponseBodyJSON ¶
func ResponseBodyString ¶
type RequestOption ¶
type RequestOption interface {
Request(*requestOptions)
}
func QueryParam ¶
func QueryParam(key, value string) RequestOption
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
interceptors/logger
command
|
|
|
observability
command
|