reqKit

package
v3.0.913 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypePlainText = "text/plain; charset=utf-8"

	ContentTypeJson = "application/json; charset=utf-8"

	ContentTypeXml = "text/xml; charset=utf-8"

	ContentTypeForm = "application/x-www-form-urlencoded; charset=utf-8"
)
View Source
const (
	// DefaultTimeout 默认超时时间
	DefaultTimeout = time.Second * 30
)

Variables

View Source
var (
	NewLogger func(output io.Writer, prefix string, flag int) req.Logger = req.NewLogger

	NewLoggerFromStandardLogger func(l *log.Logger) req.Logger = req.NewLoggerFromStandardLogger
)

Functions

func Get

func Get(ctx context.Context, url string, queryParams map[string][]string) *req.Response

Get

PS: 要注意 req.Response 结构体的 Err 字段.

@param queryParams 可以为nil

func GetAndInto added in v3.0.911

func GetAndInto(ctx context.Context, url string, queryParams map[string][]string, v interface{}) error

func GetGlobalClient added in v3.0.911

func GetGlobalClient() (client *req.Client)

func NewClient

func NewClient(options ...ClientOption) (client *req.Client)

NewClient

!!!: (1) 不要每次发请求都创建 Client,造成不必要的开销,通常可以复用同一 Client 发所有请求; (2) 自动重试(retry): 可以在返回值上自行添加.

@param options 不传参的情况下, (1) 生产模式

(2) 超时时间: 30s
(3) 跳过https证书验证
(4) 日志输出: os.Stdout
(5) 不重试

func Post

func Post(ctx context.Context, url string, body interface{}) *req.Response

Post TODO: 待验证.

PS: 要注意 req.Response 结构体的 Err 字段.

@param body Set the request Body, accepts string、[]byte、io.Reader、map and struct.

func PostAndInto added in v3.0.911

func PostAndInto(ctx context.Context, url string, body interface{}, v interface{}) error

func ReplaceGlobalClient added in v3.0.911

func ReplaceGlobalClient(client *req.Client)

func SimpleGet added in v3.0.911

func SimpleGet(ctx context.Context, url string) *req.Response

Types

type ClientOption added in v3.0.909

type ClientOption func(*clientOptions)

func WithCommonErrorResult added in v3.0.911

func WithCommonErrorResult(result interface{}) ClientOption

func WithDev added in v3.0.910

func WithDev() ClientOption

func WithInsecureSkipVerify added in v3.0.909

func WithInsecureSkipVerify(insecureSkipVerify bool) ClientOption

func WithLogger added in v3.0.909

func WithLogger(logger req.Logger) ClientOption

WithLogger

@param logger (1) 可以是 *logrus.Logger 实例 || *zap.SugaredLogger 实例

(2) 可以为nil(disable log, 禁用输出)

func WithOnAfterResponse added in v3.0.911

func WithOnAfterResponse(middleware req.ResponseMiddleware) ClientOption

func WithTimeout added in v3.0.909

func WithTimeout(timeout time.Duration) ClientOption

Jump to

Keyboard shortcuts

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