httpclient

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRetryTimes if request failed, retry 3 times at most
	DefaultRetryTimes = 3
	// DefaultRetryDelay before retry, wait and delay for 100ms
	DefaultRetryDelay = time.Millisecond * 100
)
View Source
const (
	// DefaultTTL The longest execution time for an HTTP request is 1 minute
	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 request

func Get

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

Get get request

func PatchFrom

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

PatchFrom patch form request

func PatchJSON

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

PatchJSON patch json request

func PostForm

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

PostForm post form request

func PostJSON

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

PostJSON post json request

func PutForm

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

PutForm put form request

func PutJSON

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

PutJSON put json request

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 define Mock data

type Option

type Option func(*option)

Option customize http request options

func WithHeader

func WithHeader(key, value string) Option

WithHeader set http header,can call multiple and set multiple key-value pairs

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger set logger to print key log

func WithMock

func WithMock(m Mock) Option

WithMock set mock data

func WithOnFailedAlarm

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

WithOnFailedAlarm set alert notice

func WithOnFailedRetry

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

WithOnFailedRetry set failure retry

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL The longest execution time for current HTTP request

func WithTrace

func WithTrace(t trace.T) Option

WithTrace set trace config

type ReplyErr

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

ReplyErr error response,when resp.StatusCode != http.StatusOK used for wrapper response httpCode and body 。

func ToReplyErr

func ToReplyErr(err error) (ReplyErr, bool)

ToReplyErr try to convert err to 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