clients

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDefaultSharedHTTPClient

func InitDefaultSharedHTTPClient()

InitSharedHTTPClient 使用默认配置初始化共享 HTTP Client

func InitSharedHTTPClientWithConfig

func InitSharedHTTPClientWithConfig(config *HTTPClientConfig)

InitSharedHTTPClientWithConfig 使用自定义配置初始化共享 HTTP Client

func ParseResponse

func ParseResponse[T any](data []byte, dest *T) error

func Request

func Request(req *http.Request) (data []byte, headers http.Header, httpCode int, err error)

Types

type HTTPClientConfig

type HTTPClientConfig struct {
	// 连接池配置
	MaxIdleConns        int           // 最大空闲连接数
	MaxIdleConnsPerHost int           // 每个主机的最大空闲连接数
	MaxConnsPerHost     int           // 每个主机的最大连接数
	IdleConnTimeout     time.Duration // 空闲连接超时时间

	// TLS 配置
	TLSConfig *tls.Config

	// 重定向策略
	CheckRedirect func(req *http.Request, via []*http.Request) error

	// 代理配置
	Proxy func(*http.Request) (*url.URL, error)

	// 其他传输层配置
	DisableKeepAlives  bool
	DisableCompression bool
	ForceAttemptHTTP2  bool
}

HTTPClientConfig 定义共享 HTTP Client 的配置 注意:不包含 Timeout,因为应该在 request level 通过 context 控制

Jump to

Keyboard shortcuts

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