Documentation
¶
Index ¶
Constants ¶
View Source
const ( ConstHttpRequestIdleConnTimeout = 20 * 1000 ConstInfinityQueryPerSecond = 0 )
Variables ¶
This section is empty.
Functions ¶
func GenerateRequestBody ¶
func GenerateRequestPath ¶
func GenerateRequestPath(r *resty.Request) string
Types ¶
type FeatureOpts ¶
type FeatureOpts struct { EnableMetrics bool `json:"enableMetrics,omitempty" yaml:"enableMetrics,omitempty"` // 开启 metrics 记录 EnableParseResponse bool `json:"enableParseResponse,omitempty" yaml:"enableParseResponse,omitempty"` EnableRecordContextBody bool `json:"enableRecordContextBody,omitempty" yaml:"enableRecordContextBody,omitempty"` }
func NewDefaultFeatureOpts ¶
func NewDefaultFeatureOpts() *FeatureOpts
type HttpClientConfig ¶
type HttpClientConfig struct { DisableCompression bool `json:"disableCompression,omitempty" yaml:"disableCompression,omitempty"` // 关闭 gzip 解压 DisableKeepalive bool `json:"disableKeepalive,omitempty" yaml:"disableKeepalive,omitempty"` // 关闭 keepalive 长连接 ConnTimeout uint32 `json:"connectTimeout,omitempty" yaml:"connectTimeout,omitempty"` // client 连接服务器超时时间 IdleTimeout uint32 `json:"idleTimeout,omitempty" yaml:"idleTimeout,omitempty"` // client 会话空闲超时时间 InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty"` // 忽略 https 证书校验 QueryPerSecond uint32 `json:"queryPerSecond,omitempty" yaml:"queryPerSecond,omitempty"` // 每秒最大请求数 Logger *zap.SugaredLogger `json:"-" yaml:"-"` }
func NewDefaultHttpClientConfig ¶
func NewDefaultHttpClientConfig() *HttpClientConfig
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func NewHttpClientPool ¶
func NewHttpClientPool(clientConf *HttpClientConfig, featureOpts *FeatureOpts) *Pool
func (*Pool) GetRequest ¶
func (p *Pool) GetRequest() *resty.Request
GetRequest 复用 client, 支持 http keepalive,并更新获得 client 时间 设置了 EnableParseResponse 为 false 后,需要自己手动解码返回值 Response.Body() 的字节流内容。
func (*Pool) GetRestyClient ¶
func (p *Pool) GetRestyClient() *resty.Client
GetRestyClient 获取 resty client
func (*Pool) NewRestyClient ¶
func (p *Pool) NewRestyClient() *resty.Client
NewClient 创建 resty 对象,连接不复用
func (*Pool) SetRestyClient ¶
func (p *Pool) SetRestyClient(c *resty.Client)
SetRestyClient 设置 resty client
Click to show internal directories.
Click to hide internal directories.