resty

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package resty HTTP and REST client library with parallel feature

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDialTimeout default timeout of a dialer
	DefaultDialTimeout = 5 * time.Second
	// DefaultRequestTimeout default time out of a http request
	DefaultRequestTimeout = 10 * time.Second
	// DefaultRetry retry times if a request is failed with 5xx status code
	DefaultRetry = 3
)
View Source
var CreateClient = func(t *http.Transport, timeout time.Duration) Client {
	client := &http.Client{
		Transport: t,
	}
	if timeout > 0 {
		client.Timeout = timeout
	}

	return client
}

CreateClient a function that create a client instance

Functions

This section is empty.

Types

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client http client

type Handle

type Handle func(req *http.Request, resp *http.Response, cf context.CancelFunc, err error) error

Handle handler of http response

type Option

type Option func(*Resty)

Option set restry option

func WithHeader

func WithHeader(header map[string]string) Option

WithHeader set header for http request

func WithRetry

func WithRetry(retry int) Option

WithRetry set retry times if request is failure with 5xx status code. retry is ingore if it is less than 1.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout set timeout of http request.

type Resty

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

Resty HTTP and REST client library with parallel feature

func New

func New(transport *http.Transport, handle Handle, opts ...Option) *Resty

New create a Resty instance.

func (*Resty) DoGet

func (r *Resty) DoGet(ctx context.Context, urls ...string)

DoGet execute http requests with GET method in parallel

func (*Resty) Wait

func (r *Resty) Wait() []error

Wait wait all of requests to done

type Result

type Result struct {
	Request  *http.Request
	Response *http.Response
	Err      error
}

Result result of a http request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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