httpClient

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTTL 一次http请求最长执行1分钟.
	DefaultTTL = time.Minute
)

Variables

This section is empty.

Functions

func DeleteJson

func DeleteJson(url string, requestData interface{}, options ...OptionHandler) (body []byte, httpCode int, err error)

DeleteJson delete 请求.

func GetJson

func GetJson(url string, requestData interface{}, options ...OptionHandler) (body []byte, httpCode int, err error)

GetJson get 请求.

func PatchJSON

func PatchJSON(url string, requestData interface{}, options ...OptionHandler) (body []byte, httpCode int, err error)

PatchJSON patch json 请求.

func PostJSON

func PostJSON(url string, requestData interface{}, options ...OptionHandler) (body []byte, httpCode int, err error)

PostJSON post json 请求.

func PutJSON

func PutJSON(url string, requestData interface{}, options ...OptionHandler) (body []byte, httpCode int, 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 OptionHandler

type OptionHandler func(*option)

OptionHandler 自定义设置http请求.

func WithHeader

func WithHeader(key, value string) OptionHandler

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

func WithLogger

func WithLogger(logger *zap.Logger) OptionHandler

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

func WithMock

func WithMock(m Mock) OptionHandler

WithMock 设置 mock 数据.

func WithOnFailedAlarm

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

WithOnFailedAlarm 设置告警通知.

func WithTTL

func WithTTL(ttl time.Duration) OptionHandler

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

func WithTrace

func WithTrace(t trace.T) OptionHandler

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 RequestFunc

type RequestFunc func(url string, requestData interface{}, options ...OptionHandler) (body []byte, httpCode int, err error)

Jump to

Keyboard shortcuts

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