Documentation
¶
Index ¶
Constants ¶
View Source
const ( ContentTypeJson = "application/json;charset=UTF-8" ContentTypeForm = "application/x-www-form-urlencoded" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Timeout uint `yaml:"timeout" default:"20"` //请求总的超时时间, 单位:s
MaxIdleConns uint `yaml:"max_idle_conns" default:"1000"` //最大的空闲连接数,单位:s
MaxIdleConnsPerHost uint `yaml:"max_idle_conns_per_host" default:"30"` //单个url的最大空闲连接数,单位:s
ConnectTimeout uint `yaml:"connect_timeout" default:"30"` //建立连接超时时间,单位:s
KeepAliveInterval uint `yaml:"keep_alive_interval" default:"30"` //存活探测间隔时间,单位:s
IdleConnTimeout uint `yaml:"idle_conn_timeout" default:"500"` //连接的最大空闲时间,单位:s
TLSHandshakeTimeout uint `yaml:"tls_handshake_timeout" default:"5"` //执行TLS握手的超时时间,单位:s
ExpectContinueTimeout uint `yaml:"expect_continue_timeout"` //写Header与写Body之间,等待服务端报头的超时时间
ResponseHeaderTimeout uint `yaml:"response_header_timeout"` //响应包头的最大超时时间
DisableRetry bool `yaml:"disable_retry"` //错误不重试
DisablePool bool `yaml:"disable_pool"` //禁用连接池意思是只使用短连接
Verbose *bool `yaml:"verbose" default:"false"` //是否打印请求日志
}
type HttpClient ¶
type HttpClient interface {
Get(requestId, url string, params map[string][]string, response *Response, header map[string]string) error
GetJson(requestId, url string, request interface{}, response *Response, header map[string]string) error
PostJson(requestId, url string, request interface{}, response *Response, header map[string]string) error
PostForm(requestId, url string, form map[string]interface{}, response *Response, header map[string]string) error
Put(requestId, url string, request interface{}, response *Response, header map[string]string) error
Patch(requestId, url string, request interface{}, response *Response, header map[string]string) error
Delete(requestId, url string, request interface{}, response *Response, header map[string]string) error
SetRequestIdCallBack(func(requestId string, header map[string]string))
AddHook(hook Hook)
Do(method, requestId, url, contentType string, request interface{}, values url.Values, response *Response, header map[string]string) (err error)
}
func NewHttpClient ¶
func NewHttpClient(config Config) HttpClient
Click to show internal directories.
Click to hide internal directories.