client

package
v0.0.0-...-4845449 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestTimeout        = 30 * time.Second
	HttpTimeout           = 30 * time.Second
	IdleConnTimeout       = 30 * time.Second
	TLSHandshakeTimeout   = 10 * time.Second
	ResponseHeaderTimeout = 20 * time.Second
	ExpectContinueTimeout = 2 * time.Second
	KeepAlive             = 20 * time.Second
	MaxIdleConns          = 32
	RetryCount            = 5
	RetryWaitTime         = 100 * time.Millisecond
	RetryWaitTimeMax      = 3 * time.Second
)
View Source
const LoggerPrefix = "HTTP%s\t"
View Source
const REQUESTS_BUFFER_SIZE = 10000

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client - http client.

func NewClient

func NewClient(ctx context.Context, logger log.Logger, verbose bool) *Client

func (*Client) GetRestyClient

func (c *Client) GetRestyClient() *resty.Client

func (*Client) Header

func (c *Client) Header() http.Header

func (*Client) HostUrl

func (c *Client) HostUrl() string

func (*Client) NewPool

func (c *Client) NewPool(logger log.Logger) *Pool

func (*Client) NewRequest

func (c *Client) NewRequest(method string, url string) *Request

func (*Client) Request

func (c *Client) Request(request *Request) *Request

func (*Client) Send

func (c *Client) Send(request *Request)

func (*Client) SetError

func (c *Client) SetError(err interface{}) *Client

func (*Client) SetHeader

func (c *Client) SetHeader(header, value string) *Client

func (*Client) SetRetry

func (c *Client) SetRetry(count int, waitTime time.Duration, maxWaitTime time.Duration)

func (Client) WithHostUrl

func (c Client) WithHostUrl(hostUrl string) *Client

type ErrorWithResponse

type ErrorWithResponse interface {
	SetResponse(response *resty.Response)
	HttpStatus() int
	IsBadRequest() bool
	IsUnauthorized() bool
	IsForbidden() bool
	IsNotFound() bool
}

type Logger

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

Logger for HTTP client.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

type Pool

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

Pool of the asynchronous HTTP requests. When processing a response, a new request can be send.

func (*Pool) Request

func (p *Pool) Request(request *Request) *Request

Request set request sender to pool.

func (*Pool) Send

func (p *Pool) Send(request *Request)

Send adds request to pool.

func (*Pool) SetContext

func (p *Pool) SetContext(ctx context.Context)

func (*Pool) StartAndWait

func (p *Pool) StartAndWait() error

type Request

type Request struct {
	*resty.Request
	*Response
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(id int, sender Sender, request *resty.Request) *Request

func (*Request) Id

func (r *Request) Id() int

func (*Request) IsDone

func (r *Request) IsDone() bool

func (*Request) IsSent

func (r *Request) IsSent() bool

func (*Request) MarkDone

func (r *Request) MarkDone(response *Response)

func (*Request) MarkSent

func (r *Request) MarkSent()

func (*Request) OnError

func (r *Request) OnError(callback ResponseCallback) *Request

func (*Request) OnResponse

func (r *Request) OnResponse(callback ResponseCallback) *Request

func (*Request) OnSuccess

func (r *Request) OnSuccess(callback ResponseCallback) *Request

func (*Request) Send

func (r *Request) Send() *Request

func (*Request) SetContext

func (r *Request) SetContext(ctx context.Context) *Request

func (*Request) SetFormBody

func (r *Request) SetFormBody(body map[string]string) *Request

func (*Request) SetHeader

func (r *Request) SetHeader(header string, value string) *Request

func (*Request) SetJsonBody

func (r *Request) SetJsonBody(body map[string]string) *Request

func (*Request) SetPathParam

func (r *Request) SetPathParam(param, value string) *Request

func (*Request) SetQueryParam

func (r *Request) SetQueryParam(param, value string) *Request

func (*Request) SetResult

func (r *Request) SetResult(result interface{}) *Request

func (*Request) WaitFor

func (r *Request) WaitFor(subRequest *Request)

WaitFor ensures that all main-request listeners which have not yet been executed will be deferred until sub-request will be done. All sub-request listeners defined before calling WaitFor will be executed before main-request listeners. See TestWaitForSubRequest test.

type Response

type Response struct {
	*Request
	*resty.Response
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(request *Request, response *resty.Response, err error) *Response

func (*Response) Err

func (r *Response) Err() error

func (*Response) HasError

func (r *Response) HasError() bool

func (*Response) HasResponse

func (r *Response) HasResponse() bool

func (*Response) HasResult

func (r *Response) HasResult() bool

func (*Response) Sender

func (r *Response) Sender() Sender

func (*Response) SetErr

func (r *Response) SetErr(err error) *Response

func (*Response) SetResult

func (r *Response) SetResult(result interface{}) *Response

type ResponseCallback

type ResponseCallback func(response *Response)

type ResponseEventType

type ResponseEventType int
const (
	EventOnSuccess ResponseEventType = iota
	EventOnError
	EventOnResponse // always
)

type ResponseListener

type ResponseListener struct {
	Type     ResponseEventType
	Callback ResponseCallback
}

func (*ResponseListener) Invoke

func (l *ResponseListener) Invoke(response *Response)

type Sender

type Sender interface {
	Send(r *Request)
	Request(request *Request) *Request
}

Sender of the request, client (for sync) or pool (for async).

Jump to

Keyboard shortcuts

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