clientv2

package
v7.20.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RequestMethodGet    = http.MethodGet
	RequestMethodPut    = http.MethodPut
	RequestMethodPost   = http.MethodPost
	RequestMethodHead   = http.MethodHead
	RequestMethodDelete = http.MethodDelete
)

Variables

This section is empty.

Functions

func Do

func Do(c Client, options RequestParams) (*http.Response, error)

func DoAndDecodeJsonResponse

func DoAndDecodeJsonResponse(c Client, options RequestParams, ret interface{}) error

func IsErrorRetryable

func IsErrorRetryable(err error) bool

func IsPrintRequest

func IsPrintRequest() bool

func IsPrintRequestBody

func IsPrintRequestBody() bool

func IsPrintRequestTrace

func IsPrintRequestTrace() bool

func IsPrintResponse

func IsPrintResponse() bool

func IsPrintResponseBody

func IsPrintResponseBody() bool

func NewRequest

func NewRequest(options RequestParams) (req *http.Request, err error)

func PrintRequest

func PrintRequest(level DebugLevel)

func PrintRequestTrace

func PrintRequestTrace(isPrint bool)

func PrintResponse

func PrintResponse(level DebugLevel)

func WithInterceptors added in v7.20.0

func WithInterceptors(req *http.Request, interceptors ...Interceptor) *http.Request

Types

type AuthConfig

type AuthConfig struct {
	Credentials *auth.Credentials //
	TokenType   auth.TokenType    // 不包含上传
}

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

func NewClient

func NewClient(cli Client, interceptors ...Interceptor) Client

func NewClientWithClientV1 added in v7.17.1

func NewClientWithClientV1(c *clientV1.Client) Client

type DebugLevel

type DebugLevel int
const (
	DebugLevelPrintNone   DebugLevel = 0
	DebugLevelPrintNormal DebugLevel = 1
	DebugLevelPrintDetail DebugLevel = 2
)

type GetRequestBody added in v7.20.0

type GetRequestBody func(options *RequestParams) (io.ReadCloser, error)

func GetFormRequestBody added in v7.20.0

func GetFormRequestBody(info map[string][]string) GetRequestBody

func GetJsonRequestBody added in v7.20.0

func GetJsonRequestBody(object interface{}) (GetRequestBody, error)

func GetMultipartFormRequestBody added in v7.20.0

func GetMultipartFormRequestBody(info *MultipartForm) GetRequestBody

type Handler

type Handler func(req *http.Request) (*http.Response, error)

type HostsRetryConfig

type HostsRetryConfig struct {
	RetryConfig        RetryConfig               // 主备域名重试参数
	HostFreezeDuration time.Duration             // 主备域名冻结时间(默认:600s),当一个域名请求失败被冻结的时间,最小 time.Millisecond
	HostProvider       hostprovider.HostProvider // 备用域名获取方法
	ShouldFreezeHost   func(req *http.Request, resp *http.Response, err error) bool
}

type Interceptor

type Interceptor interface {
	// Priority 数字越小优先级越高
	Priority() InterceptorPriority

	// Intercept 拦截处理函数
	Intercept(req *http.Request, handler Handler) (*http.Response, error)
}

func NewAuthInterceptor

func NewAuthInterceptor(config AuthConfig) Interceptor

func NewHostsRetryInterceptor

func NewHostsRetryInterceptor(options HostsRetryConfig) Interceptor

func NewSimpleInterceptor

func NewSimpleInterceptor(interceptorHandler func(req *http.Request, handler Handler) (*http.Response, error)) Interceptor

func NewSimpleInterceptorWithPriority

func NewSimpleInterceptorWithPriority(priority InterceptorPriority, interceptorHandler func(req *http.Request, handler Handler) (*http.Response, error)) Interceptor

func NewSimpleRetryInterceptor

func NewSimpleRetryInterceptor(config RetryConfig) Interceptor

type InterceptorPriority

type InterceptorPriority int
const (
	InterceptorPriorityDefault     InterceptorPriority = 100
	InterceptorPriorityRetryHosts  InterceptorPriority = 200
	InterceptorPriorityRetrySimple InterceptorPriority = 300
	InterceptorPrioritySetHeader   InterceptorPriority = 400
	InterceptorPriorityNormal      InterceptorPriority = 500
	InterceptorPriorityAuth        InterceptorPriority = 600
	InterceptorPriorityDebug       InterceptorPriority = 700
)

type MultipartForm added in v7.20.0

type MultipartForm struct {
	// contains filtered or unexported fields
}

func (*MultipartForm) SetFile added in v7.20.0

func (f *MultipartForm) SetFile(key, fileName string, stream compatible_io.ReadSeekCloser) *MultipartForm

func (*MultipartForm) SetValue added in v7.20.0

func (f *MultipartForm) SetValue(key, value string) *MultipartForm

type RequestParams

type RequestParams struct {
	Context        context.Context
	Method         string
	Url            string
	Header         http.Header
	GetBody        GetRequestBody
	BufferResponse bool
}

type RetryConfig

type RetryConfig struct {
	RetryMax      int                  // 最大重试次数
	RetryInterval func() time.Duration // 重试时间间隔
	ShouldRetry   func(req *http.Request, resp *http.Response, err error) bool
}

Jump to

Keyboard shortcuts

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