Documentation
¶
Index ¶
- Constants
- type HttpClient
- func (_t *HttpClient) Get(targetUrl string) (responseBody string, err error)
- func (_t *HttpClient) GetHttpCode(targetUrl string) (httpCode int, err error)
- func (_t HttpClient) GetTransport() *http.Transport
- func (_t *HttpClient) GetWithParams(targetUrl string, params url.Values) (string, error)
- func (_t *HttpClient) Post(targetUrl string, contentType string, body []byte) (responseBody string, err error)
- func (_t HttpClient) Request(targetUrl string, contentType string, body []byte) (responseBody string, httpCode int, err error)
- func (_t *HttpClient) SetNicIp(nicIp string) *HttpClient
- func (_t *HttpClient) SetProxy(proxy string) *HttpClient
- func (_t *HttpClient) SetRequestHandler(handler RequestHandler) *HttpClient
- func (_t *HttpClient) SetTimeout(timeout time.Duration) *HttpClient
- type RequestHandler
Constants ¶
View Source
const HTTP_CONTENT_TYPE_JSON string = "application/json"
View Source
const HTTP_TIMEOUT_DEFAULT time.Duration = time.Second * 10
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpClient ¶
type HttpClient struct {
Proxy string // 代理地址, 如果有配置, 使用此地址做代理
NicIp string // 网卡IP, 如果有配置, 便宜此网卡做出口
Timeout time.Duration
Method string // 访问方式, 默认GET
RequestHandler RequestHandler // 请求处理器, 可以对请求进行一些初始化操作, 比如设置头部信息等
}
func NewHttpClient ¶
func NewHttpClient() *HttpClient
func (*HttpClient) Get ¶
func (_t *HttpClient) Get(targetUrl string) (responseBody string, err error)
func (*HttpClient) GetHttpCode ¶
func (_t *HttpClient) GetHttpCode(targetUrl string) (httpCode int, err error)
func (HttpClient) GetTransport ¶
func (_t HttpClient) GetTransport() *http.Transport
func (*HttpClient) GetWithParams ¶
func (*HttpClient) SetRequestHandler ¶
func (_t *HttpClient) SetRequestHandler(handler RequestHandler) *HttpClient
设置请求处理器, 可以对请求进行一些初始化操作, 比如设置头部信息等
func (*HttpClient) SetTimeout ¶
func (_t *HttpClient) SetTimeout(timeout time.Duration) *HttpClient
设置请求超时
type RequestHandler ¶
Click to show internal directories.
Click to hide internal directories.