Documentation ¶
Index ¶
- func BindResponseBody(response *http.Response, reply any) error
- func CodecForRequest(r *http.Request, name ...string) (encoding.Codec, bool)
- func CodecForResponse(r *http.Response, name ...string) (encoding.Codec, bool)
- func CodecForString(contentType string) encoding.Codec
- func ForceHttps(endpoint string) string
- func IsTimeout(err error) bool
- func Not2xxCode(code int) bool
- func ProxyURL(address string) func(*http.Request) (*url.URL, error)
- func RegisterCodec(contentType string, codec encoding.Codec)
- func RegisterCodecName(contentType string, name string)
- func SetClient(c *Client)
- func SetQuery(req *http.Request, q any) error
- func SetRequestBody(req *http.Request, body io.Reader) error
- func StatusForErr(err error) (int, bool)
- type CallOption
- type CallOptions
- type Client
- type ClientOption
- func WithContentType(contentType string) ClientOption
- func WithDebug(open bool) ClientOption
- func WithDebugInterface(f func() DebugInterface) ClientOption
- func WithEndpoint(endpoint string) ClientOption
- func WithLimiter(l Limiter) ClientOption
- func WithNot2xxError(f func() error) ClientOption
- func WithProxy(f func(*http.Request) (*url.URL, error)) ClientOption
- func WithTLSConfig(cfg *tls.Config) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransport(transport http.RoundTripper) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type Debug
- type DebugInterface
- type Error
- type Limiter
- type RequestFunc
- type ResponseFunc
- type TraceInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CodecForRequest ¶
CodecForRequest get encoding.Codec via http.Request
func CodecForResponse ¶
CodecForResponse get encoding.Codec via http.Response
func CodecForString ¶
CodecForString get encoding.Codec via string
func ForceHttps ¶
func Not2xxCode ¶
func RegisterCodec ¶
func RegisterCodecName ¶
func StatusForErr ¶
Types ¶
type CallOption ¶
type CallOption interface { Before(request *http.Request) error After(response *http.Response) error }
func After ¶
func After(hooks ...ResponseFunc) CallOption
func BasicAuth ¶
func BasicAuth(username, password string) CallOption
func BearerToken ¶
func BearerToken(token string) CallOption
func Before ¶
func Before(hooks ...RequestFunc) CallOption
func Query ¶
func Query(q any) CallOption
type CallOptions ¶
type CallOptions struct { // Set query parameters Query any // Basic auth Username string Password string // Bearer token BearerToken string // hooks BeforeHooks []RequestFunc AfterHooks []ResponseFunc }
CallOptions default call options
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
func (*Client) SetEndpoint ¶
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is HTTP client option.
func WithContentType ¶
func WithContentType(contentType string) ClientOption
WithContentType with client request content type.
func WithDebugInterface ¶
func WithDebugInterface(f func() DebugInterface) ClientOption
WithDebugInterface sets the function to create a new DebugInterface instance.
func WithLimiter ¶
func WithLimiter(l Limiter) ClientOption
WithLimiter sets a rate limiter for the client. This limiter will be applied to control the number of requests made to the server, ensuring that the requests stay within the specified limits.
func WithNot2xxError ¶
func WithNot2xxError(f func() error) ClientOption
WithNot2xxError handle response status code < 200 and code > 299
func WithTLSConfig ¶
func WithTLSConfig(cfg *tls.Config) ClientOption
WithTLSConfig with tls config.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout with client request timeout.
func WithTransport ¶
func WithTransport(transport http.RoundTripper) ClientOption
WithTransport with http.RoundTrippe.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent with client user agent.
type Debug ¶
type Debug struct { Writer io.Writer Trace bool TraceCallback func(w io.Writer, info TraceInfo) // contains filtered or unexported fields }
type DebugInterface ¶
type RequestFunc ¶
type ResponseFunc ¶
type TraceInfo ¶
type TraceInfo struct { DNSDuration time.Duration `json:"DNSDuration,omitempty" yaml:"DNSDuration" xml:"DNSDuration"` ConnectDuration time.Duration `json:"connectDuration,omitempty" yaml:"connectDuration" xml:"connectDuration"` TLSHandshakeDuration time.Duration `json:"TLSHandshakeDuration,omitempty" yaml:"TLSHandshakeDuration" xml:"TLSHandshakeDuration"` RequestDuration time.Duration `json:"requestDuration,omitempty" yaml:"requestDuration" xml:"requestDuration"` WaitResponseDuration time.Duration `json:"waitResponseDuration,omitempty" yaml:"waitResponseDuration" xml:"waitResponseDuration"` ResponseDuration time.Duration `json:"responseDuration,omitempty" yaml:"responseDuration" xml:"responseDuration"` TotalDuration time.Duration `json:"totalDuration,omitempty" yaml:"totalDuration" xml:"totalDuration"` // contains filtered or unexported fields }