client

package
v0.0.0-...-d07672d Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConstHttpRequestIdleConnTimeout = 20 * 1000
	ConstInfinityQueryPerSecond     = 0
)

Variables

This section is empty.

Functions

func GenerateRequestBody

func GenerateRequestBody(r *resty.Request) (string, error)

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) PutRequest

func (p *Pool) PutRequest(_ interface{})

PutRequest 归还会话,空壳函数

func (*Pool) SetRestyClient

func (p *Pool) SetRestyClient(c *resty.Client)

SetRestyClient 设置 resty client

func (*Pool) Stop

func (p *Pool) Stop()

Jump to

Keyboard shortcuts

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