Documentation
¶
Overview ¶
client 包 @author cbping
Index ¶
- Constants
- func SetDefaultClient(title string, client *http.Client)
- func SetProxy(proxy func(*http.Request) (*url.URL, error))
- func SetRecord(record func(tag, msg string))
- func SetRetryCount(retryCount int)
- func SetSlowReqLong(long time.Duration)
- func SetTimeOut(timeout time.Duration)
- func SetUserAgent(userAgent string)
- func SetVersion(version string)
- type BaseRequest
- type Client
- func (c *Client) DoRequest(req Request) (resp *Response, err error)
- func (c *Client) SetDebug(debug bool)
- func (c *Client) SetProxy(proxy func(*http.Request) (*url.URL, error))
- func (c *Client) SetRecord(record func(tag, msg string))
- func (c *Client) SetRetryCount(retryCount int)
- func (c *Client) SetSlowReqLong(long time.Duration)
- func (c *Client) SetTimeOut(timeout time.Duration)
- func (c *Client) SetUserAgent(userAgent string)
- func (c *Client) SetVersion(version string)
- type Request
- type Response
- type ResponseFormat
Constants ¶
View Source
const ( SlowReqRecord = "SlowReqRecord" ReqRecord = "ReqRecord" ErrorReqRecord = "ErrorReqRecord" )
View Source
const ( JSONResponseFormat = ResponseFormat("JSON") XMLResponseFormat = ResponseFormat("XML") )
View Source
const Version = "0.2"
Variables ¶
This section is empty.
Functions ¶
func SetProxy ¶
设置代理 example:
func(req *http.Request) (*url.URL, error) {
u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
return u, nil
}
内部调用DefaultClient
func SetUserAgent ¶
func SetUserAgent(userAgent string)
func SetVersion ¶
func SetVersion(version string)
Types ¶
type BaseRequest ¶
type BaseRequest struct {
// contains filtered or unexported fields
}
请求基类
实现请求接口的基类,所有请求对象继承必须继承此基类
func (*BaseRequest) Clone ¶
func (b *BaseRequest) Clone() interface{}
func (*BaseRequest) GetTimeOut ¶
func (b *BaseRequest) GetTimeOut() time.Duration
func (*BaseRequest) HttpRequest ¶
func (b *BaseRequest) HttpRequest() (*http.Request, error)
func (*BaseRequest) SetReqCount ¶
func (b *BaseRequest) SetReqCount(reqCount int)
func (*BaseRequest) String ¶
func (b *BaseRequest) String() string
type Client ¶
客户端 处理http请求
var DefaultClient *Client
func (*Client) SetProxy ¶
设置代理 example:
func(req *http.Request) (*url.URL, error) {
u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
return u, nil
}
你也可以通过设置环境变量 HTTP_PROXY 来设置代理,如:
os.Setenv("HTTP_PROXY", "http://127.0.0.1:8888")
func (*Client) SetRetryCount ¶
func (*Client) SetSlowReqLong ¶
func (*Client) SetTimeOut ¶
func (*Client) SetUserAgent ¶
func (*Client) SetVersion ¶
type Request ¶
type Request interface {
//返回*http.Request
HttpRequest() (*http.Request, error)
//返回请求相关内容格式化字符串
String() string
// 获取超时时间
// =0代表此请求不启用超时设置
// <0代表默认使用全局
// >0代表自定义超时时间
// @deprecated 2017-09-26
GetTimeOut() time.Duration
//克隆
Clone() interface{}
//设置尝试次数
SetReqCount(reqCount int)
}
请求接口
Client接受处理的请求接口
type Response ¶
封装标准库中的Response 方便处理响应内容信息
type ResponseFormat ¶
type ResponseFormat string
Click to show internal directories.
Click to hide internal directories.