httpClient

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MulanPSL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff interface {
	Next(retry int) time.Duration
}

定义回退策略

func NewConstantBackoff

func NewConstantBackoff(backoffInterval Duration) Backoff

NewConstantBackoff 返回一个常数退避实例

func NewExponentialBackoff

func NewExponentialBackoff(initialTimeout, maxTimeout time.Duration, exponentFactor float64) Backoff

NewExponentialBackoff 返回一个指数退避实例

type Config

type Config struct {
	Dial Duration
	// Timeout    Duration
	KeepAlive  Duration
	MaxConns   int
	MaxIdle    int
	RetryCount int
}

HttpClient配置

type Duration

type Duration time.Duration

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

将文本转化为Duration结构

type HttpClient

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

HttpClient结构

func NewHttpClient

func NewHttpClient(c *Config) *HttpClient

NewHttpClient 返回一个HttpClient实例

func (*HttpClient) Do

func (c *HttpClient) Do(ctx context.Context, req *http.Request) (response *http.Response, err error)

Do 实现http重传并执行http.do

func (*HttpClient) Get

func (c *HttpClient) Get(ctx context.Context, url string, headers http.Header) (response *http.Response, err error)

Get HttpCllient Get方法实现

func (*HttpClient) Post

func (c *HttpClient) Post(ctx context.Context, url string, body io.Reader, headers http.Header) (response *http.Response, err error)

Post HttpCllient Post方法实现

func (*HttpClient) SetRetrier

func (c *HttpClient) SetRetrier(retrier Retriable)

SetRetrier 设置重连策略

func (*HttpClient) SetRetryCount

func (c *HttpClient) SetRetryCount(count int)

SetRetryCount 设置重连次数

type Retriable

type Retriable interface {
	NextInterval(retry int) time.Duration
	Do(fn RetryFunc, retries int) (err error)
}

定义retriers接口实现

func NewNoRetrier

func NewNoRetrier() Retriable

NewNoRetrier 返回不间断重试的实例

func NewRetrier

func NewRetrier(backoff Backoff) Retriable

NewRetrier 返回包含特定退避策略的retrier

func NewRetrierFunc

func NewRetrierFunc(f RetriableFunc) Retriable

NewRetrierFunc 返回一个定义了重试函数的retrier

type RetriableFunc

type RetriableFunc func(retry int) time.Duration

RetriableFunc 可以使用普通函数的适配器

func (RetriableFunc) Do

func (f RetriableFunc) Do(fn RetryFunc, retries int) (err error)

func (RetriableFunc) NextInterval

func (f RetriableFunc) NextInterval(retry int) time.Duration

NextInterval 调用f(retry)

type RetryFunc

type RetryFunc func() (err error)

func (RetryFunc) Do

func (f RetryFunc) Do() (err error)

Jump to

Keyboard shortcuts

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