reqKit

package
v3.0.53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsTimeoutError func(err error) (flag bool) = httpClientKit.IsTimeoutError

IsTimeoutError 是否是请求超时错误?

Functions

func DownloadToFile

func DownloadToFile(url, filePath string) error

func DownloadToWriter

func DownloadToWriter(url string, writer io.Writer) error

func Get

func Get(url string, queryParams map[string][]string) (code int, data []byte, err error)

func Post

func Post(url string, queryParams map[string][]string, body interface{}) (status int, data []byte, err error)

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

func NewClient(maxRetryTimes int) *Client

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) Get

func (c *Client) Get(url string, queryParams map[string][]string) (status int, data []byte, err error)

func (*Client) Post

func (c *Client) Post(url string, queryParams map[string][]string, body interface{}) (status int, data []byte, err error)

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

func (c *Client) SimplePostWithJson(url string, queryParams map[string][]string, jsonBytes []byte) (*req.Response, error)

func (*Client) SimplePostWithString

func (c *Client) SimplePostWithString(url string, queryParams map[string][]string, str string) (*req.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL