Documentation ¶
Index ¶
- Constants
- func Delete(urlRaw string, params RequestParams) (*http.Response, error)
- func DeleteURL(urlRaw string) (*http.Response, error)
- func Get(urlRaw string, params RequestParams) (*http.Response, error)
- func GetURL(urlRaw string) (*http.Response, error)
- func Httpclient() *http.Client
- func NewHeaders(ua UserAgent) map[string]string
- func NewProxy(rawurl string) (*http.Transport, error)
- func NewProxyTransport(rawurl string) (*http.Transport, error)
- func NewTransport(rawurl string) *http.Transport
- func Post(urlRaw string, params RequestParams) (*http.Response, error)
- func PostBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
- func PostJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
- func PostJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)
- func Put(urlRaw string, params RequestParams) (*http.Response, error)
- func PutBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
- func PutJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
- func PutJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)
- func ReadBody(resp *http.Response, err error) ([]byte, error)
- func ReadBodyAndHeader(resp *http.Response, err error) ([]byte, http.Header, error)
- func ReadBodyAndHeaderAndStatusCode(resp *http.Response, err error) ([]byte, http.Header, int, error)
- func ReadBodyAndStatusCode(resp *http.Response, err error) ([]byte, int, error)
- func SetProxy(proxyRaw string) error
- func SetTimeout(timeoutSecond uint)
- func SetUrlLog(fx func(a ...any))
- func SetUserAgent(ua string)
- type HttpClient
- func (c *HttpClient) DELETE(urlRaw string, params RequestParams) (*http.Response, error)
- func (c *HttpClient) GET(urlRaw string, params RequestParams) (*http.Response, error)
- func (c *HttpClient) HttpClient() *http.Client
- func (c *HttpClient) POST(urlRaw string, params RequestParams) (*http.Response, error)
- func (c *HttpClient) PUT(urlRaw string, params RequestParams) (*http.Response, error)
- func (c *HttpClient) PostBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
- func (c *HttpClient) PostJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
- func (c *HttpClient) PostJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)
- func (c *HttpClient) Proxy(proxyRaw string) *HttpClient
- func (c *HttpClient) PutBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
- func (c *HttpClient) PutJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
- func (c *HttpClient) PutJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)
- func (c *HttpClient) SetProxy(proxyRaw string) error
- func (c *HttpClient) SetTimeout(timeoutSecond uint)
- func (c *HttpClient) SetUrlLog(fx func(a ...any))
- func (c *HttpClient) SetUserAgent(ua string)
- func (c *HttpClient) Timeout(timeoutSecond uint) *HttpClient
- func (c *HttpClient) UA(ua string) *HttpClient
- type Method
- type Params
- type ParamsItem
- type RequestParams
- type UserAgent
Constants ¶
const (
ContentType = "Content-Type"
)
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete(urlRaw string, params RequestParams) (*http.Response, error)
Delete 发送DELETE表单请求
func NewProxy ¶
NewProxy 创建一个代理,用于发送请求的时候使用,假如代理链接错误,则返回&http.Transport{},error。 NewProxy("socks5://127.0.0.1:1080") NewProxy("socks5://admin:password@192.168.1.2:8888") NewProxy("http://127.0.0.1:1081") NewProxy("http://admin:password@192.168.1.2:8889")
func NewProxyTransport ¶
NewProxyTransport 创建一个代理,用于发送请求的时候使用,假如代理链接有错,则返回nil,error。 NewProxyTransport("socks5://127.0.0.1:1080") NewProxyTransport("socks5://admin:password@192.168.1.2:8888") NewProxyTransport("http://127.0.0.1:1081") NewProxyTransport("http://admin:password@192.168.1.2:8889")
func NewTransport ¶
NewTransport 创建一个代理,用于发送请求的时候使用,假如代理链接错误,则返回&http.Transport{},error。 NewTransport("socks5://127.0.0.1:1080") NewTransport("socks5://admin:password@192.168.1.2:8888") NewTransport("http://127.0.0.1:1081") NewTransport("http://admin:password@192.168.1.2:8889")
func PostBody ¶
func PostBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
PostBody 发送POST请求,请求体为body
func PostJsonMap ¶
func PostJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
PostJsonMap 发送POST请求,请求体为jsonData和params.Body合并的json编码结果
func PostJsonStruct ¶
PostJsonStruct 发送POST请求,请求体为structPointer和params.Body合并的json编码结果
func PutBody ¶
func PutBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
PutBody 发送PUT请求,请求体为body
func PutJsonMap ¶
func PutJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
PutJsonMap 发送PUT请求,请求体为jsonData和params.Body合并的json编码结果
func PutJsonStruct ¶
PutJsonStruct 发送PUT请求,请求体为structPointer和params.Body合并的json编码结果
func ReadBodyAndHeader ¶
ReadBodyAndHeader 读取响应体和响应头,丢弃其它内容。
func ReadBodyAndHeaderAndStatusCode ¶
func ReadBodyAndHeaderAndStatusCode(resp *http.Response, err error) ([]byte, http.Header, int, error)
ReadBodyAndHeaderAndStatusCode 读取响应体和响应头、响应状态码,丢弃其它内容。
func ReadBodyAndStatusCode ¶
ReadBodyAndStatusCode 读取响应体和响应状态码,丢弃其它内容。
Types ¶
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(proxyRaw string, timeoutSecond uint, ua UserAgent) *HttpClient
NewClient 创建一个http请求的客户端 proxyRaw 代理信息,空值则不使用代理;非空:"socks5://192.168.1.2:1080" "socks5://admin:password@192.168.1.2:8888" timeoutSecond 请求超时时间,秒
func Proxy ¶
func Proxy(proxyRaw string) *HttpClient
Proxy 设置临时代理 proxyRaw 代理信息,空值则不使用代理;非空:"socks5://127.0.0.1:1080" "socks5://admin:password@192.168.1.2:8888"
func (*HttpClient) DELETE ¶
func (c *HttpClient) DELETE(urlRaw string, params RequestParams) (*http.Response, error)
DELETE 发送DELETE表单请求
func (*HttpClient) GET ¶
func (c *HttpClient) GET(urlRaw string, params RequestParams) (*http.Response, error)
GET 发送GET表单请求
func (*HttpClient) HttpClient ¶
func (c *HttpClient) HttpClient() *http.Client
HttpClient 返回一个http客户端
func (*HttpClient) POST ¶
func (c *HttpClient) POST(urlRaw string, params RequestParams) (*http.Response, error)
POST 发送POST表单请求
func (*HttpClient) PUT ¶
func (c *HttpClient) PUT(urlRaw string, params RequestParams) (*http.Response, error)
PUT 发送PUT表单请求
func (*HttpClient) PostBody ¶
func (c *HttpClient) PostBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
PostBody 发送POST请求,请求体为body
func (*HttpClient) PostJsonMap ¶
func (c *HttpClient) PostJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
PostJsonMap 发送POST请求,请求体为jsonData和params.Body合并的json编码结果
func (*HttpClient) PostJsonStruct ¶
func (c *HttpClient) PostJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)
PostJsonStruct 发送POST请求,请求体为structPointer和params.Body合并的json编码结果
func (*HttpClient) Proxy ¶
func (c *HttpClient) Proxy(proxyRaw string) *HttpClient
Proxy 设置临时代理 proxyRaw 代理信息,空值则不使用代理;非空:"socks5://127.0.0.1:1080" "socks5://admin:password@192.168.1.2:8888"
func (*HttpClient) PutBody ¶
func (c *HttpClient) PutBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)
PutBody 发送PUT请求,请求体为body
func (*HttpClient) PutJsonMap ¶
func (c *HttpClient) PutJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)
PutJsonMap 发送PUT请求,请求体为jsonData和params.Body合并的json编码结果
func (*HttpClient) PutJsonStruct ¶
func (c *HttpClient) PutJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)
PutJsonStruct 发送PUT请求,请求体为structPointer和params.Body合并的json编码结果
func (*HttpClient) SetTimeout ¶
func (c *HttpClient) SetTimeout(timeoutSecond uint)
SetTimeout 设置超时时间
func (*HttpClient) SetUrlLog ¶
func (c *HttpClient) SetUrlLog(fx func(a ...any))
SetUrlLog 设置请求链接打印日志
func (*HttpClient) Timeout ¶
func (c *HttpClient) Timeout(timeoutSecond uint) *HttpClient
Timeout 设置临时超时时间
type Params ¶
type Params struct { Header []ParamsItem `json:"header"` Query []ParamsItem `json:"query"` Body []ParamsItem `json:"body"` }
type ParamsItem ¶
type RequestParams ¶
func Merge ¶
func Merge(global RequestParams, local RequestParams, custom RequestParams) RequestParams
Merge 将 local 合并到 global,然后将 custom 合并到 global ,最后返回 global。
func NewRequestParams ¶
func NewRequestParams() RequestParams
func ParseParamsString ¶
func ParseParamsString(ps ...string) (RequestParams, error)
ParseParamsString 解析指定格式的参数json,内容格式必须是 Params 的json编码结果。
type UserAgent ¶
type UserAgent string
const ( UaPcWinMicrosoftEdge UserAgent = `` /* 129-byte string literal not displayed */ UaPcWinFirefox UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0` UaPcWinGoogleChrome UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36` UaPcWin360Browser UserAgent = `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36` UaPcWin360JiSuBrowser UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4621.0 Safari/537.36` UaPcWinSougouBrowser UserAgent = `` /* 127-byte string literal not displayed */ UaAndroidUCBrowser UserAgent = `` /* 159-byte string literal not displayed */ UaAndroidHuaWeiBrowser UserAgent = `` /* 134-byte string literal not displayed */ )