requests

package
v1.2.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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

func New

func New() Requests

New create new requests instance

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response hold response context & data with debug information

func (*Response) Bytes added in v1.0.10

func (t *Response) Bytes() ([]byte, error)

Bytes get response as bytes data

func (*Response) Close

func (t *Response) Close()

Close release response

func (*Response) Dump

func (t *Response) Dump(body bool) map[string]interface{}

Dump dump request & response

func (*Response) Err

func (t *Response) Err() error

Err get error

func (*Response) Header added in v1.0.10

func (t *Response) Header() http.Header

Header get header

func (*Response) JSON

func (t *Response) JSON(obj interface{}) error

JSON Unmarshal response as JSON

func (*Response) RawResponse

func (t *Response) RawResponse() *http.Response

RawResponse get raw response (http.Response)

func (*Response) StatusCode

func (t *Response) StatusCode() int

StatusCode get response status code

func (*Response) Text added in v1.0.10

func (t *Response) Text() (string, error)

Text get response as plain text

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL