httpclient

package
v0.0.0-...-2a0956d Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout         = time.Second * 30
	DefaultDialTimeout     = time.Second * 30
	DefaultIDleConnTimeout = time.Second * 90
)

Variables

This section is empty.

Functions

func GetRestyClient

func GetRestyClient(cfg Config) *resty.Client

func InitHTTPClient

func InitHTTPClient(conf Config, logger *zap.Logger)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}
var HTTPClient *Client

func NewClient

func NewClient(config Config, logger *zap.Logger) *Client

func (Client) EncodeWithSha256

func (c Client) EncodeWithSha256(rawStr string) (string, error)

func (Client) Get

func (c Client) Get(ctx context.Context, url string, headers map[string]string, pathParams, queryParams map[string]string, result interface{}) ([]byte, error)

func (Client) JoinStringsInASCII

func (c Client) JoinStringsInASCII(data map[string]interface{}, sep string, includeEmpty bool, exceptKeys ...string) string

JoinStringsInASCII 排序 data 排序内容 sep 连接符 includeEmpty 是否包含空值,true则包含空值,否则不包含,注意此参数不影响参数名的存在 exceptKeys 被排除的参数名,不参与排序及拼接

func (Client) Post

func (c Client) Post(ctx context.Context, url string, headers map[string]string, body interface{}, result interface{}) ([]byte, error)

func (Client) PostForm

func (c Client) PostForm(ctx context.Context, url string, param map[string]string, result interface{}) ([]byte, error)

func (Client) SetProxy

func (c Client) SetProxy(proxyUrl string)

func (Client) ToMap

func (c Client) ToMap(context interface{}) (map[string]interface{}, error)

ToMap 转map

type Config

type Config struct {
	Debug               bool   `toml:"Debug" yaml:"debug"`
	Verbose             bool   `toml:"Verbose" yaml:"verbose" default:"false"`                           // 请求输出详细的调试信息
	Timeout             string `toml:"Timeout" yaml:"timeout" default:"5s"`                              // 请求超时时间
	DialTimeout         string `toml:"DialTimeout" yaml:"dial_timeout" default:"30s"`                    // 连接池DialTimeout
	IdleConnTimeout     string `toml:"IdleConnTimeout" yaml:"idle_conn_timeout" default:"90s"`           // 连接空闲最长时间
	MaxIdleConns        int    `toml:"MaxIdleConns" yaml:"max_idle_conns" default:"0"`                   // 最大空闲
	MaxIdleConnsPerHost int    `toml:"MaxIdleConnsPerHost" yaml:"max_idle_conns_per_host" default:"500"` // 单个host最大空闲
	MaxConnsPerHost     int    `toml:"MaxConnsPerHost" yaml:"max_conns_per_host" default:"2000"`         // 单个host允许最大连接
	DisableKeepAlives   bool   `toml:"DisableKeepAlives" yaml:"disable_keep_alives"`                     // 为true时,强制禁用HTTP协议的keep-alive功能
}

func (Config) GetHTTPDialTimeout

func (cfg Config) GetHTTPDialTimeout() time.Duration

func (Config) GetHTTPIdleConnTimeout

func (cfg Config) GetHTTPIdleConnTimeout() time.Duration

func (Config) GetHTTPTimeout

func (cfg Config) GetHTTPTimeout() time.Duration

Jump to

Keyboard shortcuts

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