Documentation ¶
Index ¶
Constants ¶
View Source
const (
DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cfg ¶
type Cfg struct { // basic Url string `toml:"url"` Codec ht.Codec `toml:"codec"` Method REST_METHOD `toml:"method"` Headers map[string]string `toml:"headers"` FailRetry int `toml:"fail_retry"` FailRetryInterval time.Duration `toml:"fail_retry_interval"` // dial DialTimeout time.Duration `toml:"dial_timeout"` // 连接超时时间 DialDisableKeepAlive bool `toml:"dial_disable_keep_alive"` // pool PoolMaxIdle int `toml:"pool_max_idle"` // 所有host最大空闲连接数 PoolMaxIdlePerHost int `toml:"pool_max_idle_per_host"` // 每个host最大空闲连接数 PoolIdleTimeout time.Duration `toml:"pool_idle_time"` // 闲置连接的过期时间 }
type REST_METHOD ¶
type REST_METHOD string
const ( REST_METHOD_GET REST_METHOD = "get" REST_METHOD_POST REST_METHOD = "post" REST_METHOD_JSON_POST REST_METHOD = "json_post" REST_METHOD_FILE_POST REST_METHOD = "file_post" REST_METHOD_BYTES_POST REST_METHOD = "bytes_post" )
type RestClientPool ¶
type RestClientPool struct {
// contains filtered or unexported fields
}
func NewRestClientPool ¶
func NewRestClientPool(cfg *Cfg) *RestClientPool
func Pool ¶
func Pool(name string) (r *RestClientPool)
func SafePool ¶
func SafePool(name string) (r *RestClientPool, err error)
func (*RestClientPool) Call ¶
func (this *RestClientPool) Call(headers map[string]string, params interface{}, body interface{}, resp interface{}) (r *http.Response, err error)
注意:当resp不指定值时,需要手动进行response.Body.Close()
func (*RestClientPool) SetHeader ¶
func (this *RestClientPool) SetHeader(key string, value string)
Click to show internal directories.
Click to hide internal directories.