httpclient

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 13 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, statusCode int, err error)

Delete delete 请求

func Get

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

Get get 请求

func PatchFromBody added in v1.1.16

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

PatchFromBody patch form 请求

func PatchJSONBody added in v1.1.16

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

PatchJSONBody patch json 请求

func PatchNoBody added in v1.1.16

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

PatchNoBody patch 请求

func PostFormBody added in v1.1.16

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

PostFormBody post form 请求

func PostJSONBody added in v1.1.16

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

PostJSONBody post json 请求

func PostNoBody added in v1.1.16

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

PostNoBody post 请求

func PutFormBody added in v1.1.16

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

PutFormBody put form 请求

func PutJSONBody added in v1.1.16

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

PutJSONBody put json 请求

func PutNoBody added in v1.1.16

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

PutNoBody put 请求

func QueryUnescape

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

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 WithNewJournal

func WithNewJournal(id string) Option

WithNewJournal 创建新的Journal用于记录

func WithPrintJournal

func WithPrintJournal(desc string) Option

WithPrintJournal 打印journal

func WithQueryForm added in v1.1.16

func WithQueryForm(form url.Values) Option

WithQueryForm 添加queryform(仅对 PostWithBody PutWithBody PatchWithBody 有效)

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