cHTTPClient

package module
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPMethod

type HTTPMethod string
const (
	MethodHEAD    HTTPMethod = "HEAD"
	MethodGET     HTTPMethod = "GET"
	MethodPOST    HTTPMethod = "POST"
	MethodOPTIONS HTTPMethod = "OPTIONS"
	MethodDELETE  HTTPMethod = "DELETE"
	MethodPUT     HTTPMethod = "PUT"
	MethodPATCH   HTTPMethod = "PATCH"
	MethodTRACE   HTTPMethod = "TRACE"
	MethodCONNECT HTTPMethod = "CONNECT"
)

type Option

type Option struct {
	Host           string            // 域名
	Uri            string            // 路由
	Method         HTTPMethod        // 方法
	Timeout        time.Duration     // 总超时时间
	ConnectTimeout time.Duration     // 连接超时时间
	Try            int               // 重试次数, 小于 0 则永久重试
	Interval       int               // 重试间隔, 每间隔 interval 秒进行一次请求
	IntervalIncr   int               // 重试间隔递增值, 间隔时间从 interval 开始, 每次重试都会递增 interval_incr 秒
	IntervalTry    int               // 重试间隔递增请求次数阈值, 每次递增后尝试请求 interval_try 次, 再执行下一次递增
	IntervalMax    int               // 重试间隔最大值, 超过该值则间隔时间不再递增
	Headers        map[string]string // 请求头
	Query          map[string]string // 路由参数
	Data           string            // POST 参数

	Stream          chan string                                                             `json:"-"`
	ResponseHandler func(ctx *gin.Context, response *http.Response) (retry bool, err error) `json:"-"`
}

type Response added in v0.0.52

type Response struct {
	Header     http.Header
	Status     string
	StatusCode int
	Body       []byte `json:"-"`
}

func Request

func Request(ctx *gin.Context, option Option) (response *Response, err error)

Jump to

Keyboard shortcuts

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