Documentation ¶
Index ¶
- Variables
- func DownloadToFile(url, filePath string) error
- func DownloadToWriter(url string, writer io.Writer) error
- func Get(url string, queryParams map[string][]string) (code int, data []byte, err error)
- func Post(url string, queryParams map[string][]string, body interface{}) (status int, data []byte, err error)
- type Client
- func (c *Client) Get(url string, queryParams map[string][]string) (status int, data []byte, err error)
- func (c *Client) Post(url string, queryParams map[string][]string, body interface{}) (status int, data []byte, err error)
- func (c *Client) SimpleGet(url string, queryParams map[string][]string) (resp *req.Response, err error)
- func (c *Client) SimplePost(url string, queryParams map[string][]string, body interface{}) (*req.Response, error)
- func (c *Client) SimplePostWithJson(url string, queryParams map[string][]string, jsonBytes []byte) (*req.Response, error)
- func (c *Client) SimplePostWithString(url string, queryParams map[string][]string, str string) (*req.Response, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var IsTimeoutError func(err error) (flag bool) = httpClientKit.IsTimeoutError
IsTimeoutError 是否是请求超时错误?
Functions ¶
func DownloadToFile ¶
Types ¶
type Client ¶
type Client struct { *req.Client // contains filtered or unexported fields }
func GetDefaultClient ¶
func GetDefaultClient() *Client
GetDefaultClient
重用Client https://req.cool/zh/docs/tutorial/best-practices/#%e9%87%8d%e7%94%a8-client
不要每次发请求都创建 Client,造成不必要的开销,通常可以复用 同一Client 发所有请求.
!!!: (1) 不修改返回值的话,可以调用此方法;否则调用 NewClient; (2) 最大重试次数 == 3.
func NewClient ¶
NewClient
参考: 使用req封装SDK https://req.cool/zh/docs/prologue/quickstart/#%e4%bd%bf%e7%94%a8-req-%e5%b0%81%e8%a3%85-sdk
func (*Client) SimpleGet ¶
func (c *Client) SimpleGet(url string, queryParams map[string][]string) (resp *req.Response, err error)
SimpleGet
!!!: (1) 第2个返回值==nil的情况下,不需要手动关闭第1个返回值; (2) 最大重试次数,参考了 eatmoreapple/openwechat 中的 client.go.
func (*Client) SimplePost ¶
func (c *Client) SimplePost(url string, queryParams map[string][]string, body interface{}) (*req.Response, error)
SimplePost
参考: 基础POST请求 https://req.cool/zh/docs/prologue/quickstart/#%e5%9f%ba%e7%a1%80-post-%e8%af%b7%e6%b1%82
PS: (1) Content-Type为"application/json; charset=utf-8".
func (*Client) SimplePostWithJson ¶
Click to show internal directories.
Click to hide internal directories.