httpclient

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTTL 一次http请求最长执行10秒钟
	DefaultTTL = time.Second * 10
	// DefaultRetryTimes 如果请求失败,最多重试3次
	DefaultRetryTimes = 3
	// DefaultRetryDelay 在重试前,延迟等待100毫秒
	DefaultRetryDelay = time.Millisecond * 100
)

Variables

This section is empty.

Functions

func Delete

func Delete(url string, form httpURL.Values, options ...Option) (body []byte, header http.Header, err error)

Delete delete 请求

func Get

func Get(url string, form httpURL.Values, options ...Option) (body []byte, header http.Header, err error)

Get get 请求

func PatchFrom

func PatchFrom(url string, form httpURL.Values, options ...Option) (body []byte, header http.Header, err error)

PatchFrom patch form 请求

func PatchJSON

func PatchJSON(url string, raw json.RawMessage, options ...Option) (body []byte, header http.Header, err error)

PatchJSON patch json 请求

func PostForm

func PostForm(url string, form httpURL.Values, options ...Option) (body []byte, header http.Header, err error)

PostForm post form 请求

func PostJSON

func PostJSON(url string, raw json.RawMessage, options ...Option) (body []byte, header http.Header, err error)

PostJSON post json 请求

func PutForm

func PutForm(url string, form httpURL.Values, options ...Option) (body []byte, header http.Header, err error)

PutForm put form 请求

func PutJSON

func PutJSON(url string, raw json.RawMessage, options ...Option) (body []byte, header http.Header, err error)

PutJSON put json 请求

func QueryUnescape added in v1.2.4

func QueryUnescape(uri string) string

func ToReplyErr

func ToReplyErr(err error) (statusCode int, _ error, _ bool)

ToReplyErr 尝试将err转换为ReplyErr

Types

type Journal

type Journal = journal.T

Journal 记录内部流转信息

type Option

type Option func(*option)

Option 自定义设置http请求

func WithContext added in v1.2.2

func WithContext(ctx context.Context) Option

WithContext ttl会基于此ctx做计时

func WithHeader

func WithHeader(key, value string) Option

WithHeader 设置http header,可以调用多次设置多对key-value

func WithJournal

func WithJournal(j Journal) Option

WithJournal 设置Journal以便记录内部流转信息

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger 设置logger以便打印关键日志

func WithMarshalJournal added in v1.2.3

func WithMarshalJournal() Option

WithMarshalJournal 序列化journal

func WithNewJournal added in v1.2.3

func WithNewJournal(id string) Option

WithNewJournal 创建新的Journal用于记录

func WithPrintJournal added in v1.2.3

func WithPrintJournal(desc string) Option

WithPrintJournal 打印journal

func WithRetryDelay

func WithRetryDelay(retryDelay time.Duration) Option

WithRetryDelay 在重试前,延迟等待一会

func WithRetryTimes

func WithRetryTimes(retryTimes int) Option

WithRetryTimes 如果请求失败,最多重试N次

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL 本次http请求最长执行时间

type ReplyErr

type ReplyErr interface {
	error
	// contains filtered or unexported methods
}

ReplyErr 错误响应,当resp.StatusCode != http.StatusOK时用来包装返回的信息。

Jump to

Keyboard shortcuts

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