httpclient

package
v0.0.0-...-c1ac247 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Delete

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

Delete delete 请求

func Get

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

Get get 请求

func PatchFrom

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

PatchFrom patch form 请求

func PatchJSON

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

PatchJSON patch json 请求

func PostForm

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

PostForm post form 请求

func PostJSON

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

PostJSON post json 请求

func PutForm

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

PutForm put form 请求

func PutJSON

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

PutJSON put json 请求

Types

type AlarmObject

type AlarmObject interface {
	Send(subject, body string) error
}

type AlarmVerify

type AlarmVerify func(body []byte) (shouldAlarm bool)

AlarmVerify Verify parse the body and verify that it is correct

type Mock

type Mock func() (body []byte)

Mock 定义接口Mock数据

type Option

type Option func(*option)

Option 自定义设置http请求

func WithHeader

func WithHeader(key, value string) Option

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

func WithLogger

func WithLogger(logger *zap.Logger) Option

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

func WithMock

func WithMock(m Mock) Option

WithMock 设置 mock 数据

func WithOnFailedAlarm

func WithOnFailedAlarm(alarmTitle string, alarmObject AlarmObject, alarmVerify AlarmVerify) Option

WithOnFailedAlarm 设置告警通知

func WithOnFailedRetry

func WithOnFailedRetry(retryTimes int, retryDelay time.Duration, retryVerify RetryVerify) Option

WithOnFailedRetry 设置失败重试

func WithTTL

func WithTTL(ttl time.Duration) Option

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

func WithTrace

func WithTrace(t trace.T) Option

WithTrace 设置trace信息

type ReplyErr

type ReplyErr interface {
	error
	StatusCode() int
	Body() []byte
}

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

func ToReplyErr

func ToReplyErr(err error) (ReplyErr, bool)

ToReplyErr 尝试将 err 转换为 ReplyErr

type RetryVerify

type RetryVerify func(body []byte) (shouldRetry bool)

RetryVerify Verify parse the body and verify that it is correct

Jump to

Keyboard shortcuts

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