Documentation ¶
Index ¶
- Constants
- type Requests
- type Response
- func (t *Response) Bytes() ([]byte, error)
- func (t *Response) Close()
- func (t *Response) Dump(body bool) map[string]interface{}
- func (t *Response) Err() error
- func (t *Response) Header() http.Header
- func (t *Response) JSON(obj interface{}) error
- func (t *Response) RawResponse() *http.Response
- func (t *Response) StatusCode() int
- func (t *Response) Text() (string, error)
- type RetryStrategy
Constants ¶
View Source
const ( ContentTypeJSON = "application/json; charset=utf-8" // content type json ContentTypeForm = "application/x-www-form-urlencoded; charset=utf-8" // context type form ContentTypeText = "text/plain; charset=utf-8" // content type text HeaderXRequestID = "X-Request-ID" // header field for request id )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Requests ¶ added in v1.2.0
type Requests interface { // WithClient replace default http client WithClient(client *http.Client) Requests // WithContext set context WithContext(ctx context.Context) Requests // Retry set retry strategy Retry(retry RetryStrategy) Requests // Method set http request method Method(method string) Requests // Uri set uri Uri(uri string) Requests // Get set get method with uri Get(uri string) Requests // Post set post method with uri Post(uri string) Requests // Delete set delete method with uri Delete(uri string) Requests // Put set put method with uri Put(uri string) Requests // Patch set patch method with uri Patch(uri string) Requests // Query set query params Query(query url.Values) Requests // Form set form params Form(form url.Values) Requests // JSONBody set json data as body and set request content type is JSON JSONBody(data interface{}) Requests // Body set body as io reader from stream request Body(body io.Reader) Requests // Data set body is raw bytes data Data(data []byte) Requests // ContentType set content type ContentType(contentType string) Requests // UserAgent set ua UserAgent(userAgent string) Requests // RequestId set request id pass to target (endpoint) RequestId(requestId string) Requests // AddHeader add request header AddHeader(key, value string) Requests // Do requests Do() *Response }
Requests request interface
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response hold response context & data with debug information
func (*Response) RawResponse ¶
RawResponse get raw response (http.Response)
func (*Response) StatusCode ¶
StatusCode get response status code
type RetryStrategy ¶
type RetryStrategy interface { // NextBackoff returns the next backoff duration. NextBackoff() time.Duration }
RetryStrategy
func ExponentialBackoff ¶
func ExponentialBackoff(min, max time.Duration) RetryStrategy
ExponentialBackoff strategy is an optimization strategy with a retry time of 2**n milliseconds (n means number of times). You can set a minimum and maximum value, the recommended minimum value is not less than 16ms.
func LimitLinearRetry ¶
func LimitLinearRetry(backoff time.Duration, max int) RetryStrategy
LimitLinearRetry
func LimitRetry ¶
func LimitRetry(s RetryStrategy, max int) RetryStrategy
LimitRetry limits the number of retries to max attempts
func LinearBackoff ¶
func LinearBackoff(backoff time.Duration) RetryStrategy
LinearBackoff allows retries regularly with intervals
Click to show internal directories.
Click to hide internal directories.