Documentation ¶
Index ¶
- func ShouldRetry(err error) bool
- type BasicAuth
- type BeforeRequestHook
- type Cast
- type Error
- type FormData
- type LogHook
- type Monitor
- type Request
- func (r *Request) AddHeader(vv ...string)
- func (r *Request) Connect() *Request
- func (r *Request) Delete() *Request
- func (r *Request) Get() *Request
- func (r *Request) Head() *Request
- func (r *Request) HeaderExist(h string) bool
- func (r *Request) Method(method string) *Request
- func (r *Request) Options() *Request
- func (r *Request) Patch() *Request
- func (r *Request) Post() *Request
- func (r *Request) Put() *Request
- func (r *Request) RawRequest() *http.Request
- func (r *Request) ReqBody() ([]byte, error)
- func (r *Request) SetHeader(vv ...string) *Request
- func (r *Request) Trace() *Request
- func (r *Request) WithCircuit(name string) *Request
- func (r *Request) WithCustomBody(contentType string, body []byte) *Request
- func (r *Request) WithFormURLEncodedBody(body interface{}) *Request
- func (r *Request) WithHeader(header http.Header) *Request
- func (r *Request) WithJSONBody(body interface{}) *Request
- func (r *Request) WithMultipartFormDataBody(formData ...*FormData) *Request
- func (r *Request) WithPath(path string) *Request
- func (r *Request) WithPathParam(pathParam map[string]interface{}) *Request
- func (r *Request) WithPlainBody(body string) *Request
- func (r *Request) WithQueryParam(queryParam interface{}) *Request
- func (r *Request) WithTimeout(timeout time.Duration) *Request
- func (r *Request) WithXMLBody(body interface{}) *Request
- type RequestHook
- type Response
- func (resp *Response) AddHeader(vv ...string) *Response
- func (resp *Response) Body() []byte
- func (resp *Response) Cookies() []*http.Cookie
- func (resp *Response) DecodeFromJSON(v interface{}) error
- func (resp *Response) DecodeFromXML(v interface{}) error
- func (resp *Response) Header() http.Header
- func (resp *Response) Method() string
- func (resp *Response) SetHeader(vv ...string) *Response
- func (resp *Response) Size() int64
- func (resp *Response) StatusCode() int
- func (resp *Response) StatusOk() bool
- func (resp *Response) String() string
- func (resp *Response) Success() bool
- func (resp *Response) URL() string
- type RetryHook
- type Setter
- func AddBeforeRequestHook(hks ...BeforeRequestHook) Setter
- func AddCircuitConfig(name string, config ...circuit.Config) Setter
- func AddHeader(vv ...string) Setter
- func AddRequestHook(hks ...RequestHook) Setter
- func AddResponseHooks(hooks ...responseHook) Setter
- func AddRetryHooks(hooks ...RetryHook) Setter
- func SetHeader(vv ...string) Setter
- func WithBaseURL(url string) Setter
- func WithBasicAuth(username, password string) Setter
- func WithBearerToken(token string) Setter
- func WithCertificates(certificates ...tls.Certificate) Setter
- func WithConstantBackoffStrategy(internal time.Duration) Setter
- func WithCookies(cookies ...*http.Cookie) Setter
- func WithDefaultCircuit(name string) Setter
- func WithExponentialBackoffDecorrelatedJitterStrategy(base, capacity time.Duration) Setter
- func WithExponentialBackoffEqualJitterStrategy(base, capacity time.Duration) Setter
- func WithExponentialBackoffFullJitterStrategy(base, capacity time.Duration) Setter
- func WithExponentialBackoffStrategy(base, capacity time.Duration) Setter
- func WithHTTPClientTimeout(timeout time.Duration) Setter
- func WithHeader(h http.Header) Setter
- func WithLinearBackoffStrategy(slope time.Duration) Setter
- func WithLogHook(f LogHook) Setter
- func WithLogLevel(l logrus.Level) Setter
- func WithRetry(retry int) Setter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShouldRetry ¶
ShouldRetry returns whether an error needs to be retried.
Types ¶
type BasicAuth ¶
type BasicAuth struct {
// contains filtered or unexported fields
}
BasicAuth provides info to authenticate
type BeforeRequestHook ¶
BeforeRequestHook 请求之前执行的函数
type Cast ¶
type Cast struct {
// contains filtered or unexported fields
}
Cast provides a set of rules to its request.
func (*Cast) NewRequest ¶
NewRequest returns an instance of Request.
func (*Cast) SetInsecureSkipVerify ¶
SetInsecureSkipVerify set the InsecureSkipVerify value.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the http.Request wrapper with attributes.
func (*Request) HeaderExist ¶
HeaderExist whether specified header exists.
func (*Request) RawRequest ¶
RawRequest returns the http request.
func (*Request) WithCircuit ¶
WithCircuit is equipped with circuit.
func (*Request) WithCustomBody ¶
WithCustomBody creates custom body.
func (*Request) WithFormURLEncodedBody ¶
WithFormURLEncodedBody creates body with url encoded string.
func (*Request) WithHeader ¶
WithHeader replaces the request header.
func (*Request) WithJSONBody ¶
WithJSONBody creates body with JSON.
func (*Request) WithMultipartFormDataBody ¶
WithMultipartFormDataBody creates body with form data
func (*Request) WithPath ¶
WithPath set the relative or absolute path for the http request if the base url don't be provided.
func (*Request) WithPathParam ¶
WithPathParam sets path parameters.
func (*Request) WithPlainBody ¶
WithPlainBody creates body with plain text.
func (*Request) WithQueryParam ¶
WithQueryParam sets query parameters.
func (*Request) WithTimeout ¶
WithTimeout sets the request timeout.
func (*Request) WithXMLBody ¶
WithXMLBody creates body with XML.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response wraps the raw response with attributes.
func (*Response) DecodeFromJSON ¶
DecodeFromJSON decodes the JSON body into data variable.
func (*Response) DecodeFromXML ¶
DecodeFromXML decodes the XML body into data variable.
func (*Response) StatusCode ¶
StatusCode returns http status code.
type Setter ¶
Setter can change the cast instance
func AddBeforeRequestHook ¶
func AddBeforeRequestHook(hks ...BeforeRequestHook) Setter
AddBeforeRequestHook adds a before request hook.
func AddCircuitConfig ¶
AddCircuitConfig loads a circuit config.
func AddRequestHook ¶
func AddRequestHook(hks ...RequestHook) Setter
AddRequestHook adds a request hook.
func AddResponseHooks ¶
func AddResponseHooks(hooks ...responseHook) Setter
AddResponseHooks adds hooks that can be triggered when a request finished.
func AddRetryHooks ¶
AddRetryHooks adds hooks that can be triggered when in customized conditions
func WithBaseURL ¶
WithBaseURL sets the consistent part of your address.
func WithBasicAuth ¶
WithBasicAuth enables basic auth.
func WithBearerToken ¶
WithBearerToken enables bearer authentication.
func WithCertificates ¶ added in v1.4.4
func WithCertificates(certificates ...tls.Certificate) Setter
func WithConstantBackoffStrategy ¶
WithConstantBackoffStrategy changes the retry strategy called "Constant".
func WithCookies ¶
WithCookies replaces the underlying cookies which can be sent to server when initiate a request.
func WithDefaultCircuit ¶
WithDefaultCircuit sets the default circuit breaker.
func WithExponentialBackoffDecorrelatedJitterStrategy ¶
WithExponentialBackoffDecorrelatedJitterStrategy changes the retry strategy called “Decorrelated Jitter”.
func WithExponentialBackoffEqualJitterStrategy ¶
WithExponentialBackoffEqualJitterStrategy changes the retry strategy called "Equal Jitter".
func WithExponentialBackoffFullJitterStrategy ¶
WithExponentialBackoffFullJitterStrategy changes the retry strategy called "Full Jitter".
func WithExponentialBackoffStrategy ¶
WithExponentialBackoffStrategy changes the retry strategy called "Exponential".
func WithHTTPClientTimeout ¶
WithHTTPClientTimeout sets the underlying http client timeout.
func WithLinearBackoffStrategy ¶
WithLinearBackoffStrategy changes the retry strategy called "Linear".
func WithLogHook ¶
WithLogHook sets a log callback when condition is achieved.