request

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBackOff = &backoff.ExponentialBackOff{
		InitialInterval:     200 * time.Millisecond,
		RandomizationFactor: backoff.DefaultRandomizationFactor,
		Multiplier:          backoff.DefaultMultiplier,
		MaxInterval:         5 * time.Second,
		MaxElapsedTime:      10 * time.Second,
		Clock:               backoff.SystemClock,
	}

	DefaultNotify = func(err error, t time.Duration) {
		log.Printf("BackOff err: %+v, retry duration: %d ms", err, t.Milliseconds())
	}
)

Functions

func CopyBody

func CopyBody(resp *http.Response) ([]byte, error)

func CreateFormPayload

func CreateFormPayload(textFields, fileFields map[string]string) (*bytes.Buffer, error)

func CreateJSONPayload

func CreateJSONPayload(data map[string]interface{}) (body *bytes.Buffer, err error)

func Error

func Error(resp *http.Response) error

func RandomUA

func RandomUA() string

func ReadBody

func ReadBody(resp *http.Response) ([]byte, error)

Types

type BackOffClient added in v1.0.6

type BackOffClient struct {
	BackOff backoff.BackOff
	Notify  func(error, time.Duration)
}

func (*BackOffClient) Do added in v1.0.6

func (c *BackOffClient) Do(client *http.Client, req *http.Request) (*http.Response, error)

type Request added in v1.1.0

type Request struct {
	HttpClient    *http.Client
	BackOffClient *BackOffClient

	BaseURL        string
	DefaultHeaders map[string]string
	DefaultCookies []*http.Cookie
}

func (*Request) Get added in v1.1.0

func (r *Request) Get(endpoint string, params *url.Values, headers map[string]string, cookies []*http.Cookie) (*http.Response, error)

func (*Request) Post added in v1.1.0

func (r *Request) Post(endpoint string, params *url.Values, body io.Reader, headers map[string]string, cookies []*http.Cookie) (*http.Response, error)

Jump to

Keyboard shortcuts

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