httpClient

package
v0.0.0-...-5693655 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	T3s     = 3
	T5s     = 5
	T10s    = 10
	T15s    = 15
	T30s    = 30
	T60s    = 60
	T90s    = 90
	T120s   = 120
	T180s   = 180
	T300s   = 300
	T3600s  = 3600
	T7200s  = 7200
	T14400s = 14400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// 连接池
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	IdleConnTimeout     time.Duration
	TLSHandshakeTimeout time.Duration
	Expect100Timeout    time.Duration
	DialTimeout         time.Duration
	KeepAlive           time.Duration

	// 重试
	RetryCount   int
	RetryWaitMin time.Duration
	RetryWaitMax time.Duration

	// TLS(仅测试环境建议使用)
	InsecureSkipVerify bool

	// 通用 Header/UA
	UserAgent    string
	CommonHeader map[string]string

	// 需要的超时档位(秒)
	TimeoutProfiles []int
}

type Pool

type Pool struct {
	// contains filtered or unexported fields
}
var Default *Pool

Default 默认全局池:直接 httpClient.Default.C(httpClient.T30s) 取用

func NewPool

func NewPool(opt Options) *Pool

NewPool 初始化

func (*Pool) C

func (p *Pool) C(seconds int) *resty.Client

C 返回指定超时档位(秒)的 client,如 C(30)/C(120)

func (*Pool) CloseIdle

func (p *Pool) CloseIdle()

CloseIdle 在退出前或网络切换后清理空闲连接

func (*Pool) StartAutoCloseIdle

func (p *Pool) StartAutoCloseIdle(ctx context.Context, interval time.Duration, onChange func(string, string))

StartAutoCloseIdle 开启网络环境监控:当网卡/地址指纹变化时,自动调用 CloseIdle()

Jump to

Keyboard shortcuts

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