clientv2

package
v7.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 34 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 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 credentials.CredentialsProvider
	// 鉴权类型,不包含上传
	TokenType auth.TokenType
	// 签名前回调函数
	BeforeSign func(*http.Request)
	// 签名后回调函数
	AfterSign func(*http.Request)
	// 签名失败回调函数
	SignError func(*http.Request, error)
}

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 {
	RetryMax           int // 最大重试次数
	ShouldRetry        func(req *http.Request, resp *http.Response, err error) bool
	Retrier            retrier.Retrier           // 重试器
	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 NewAntiHijackingInterceptor added in v7.22.0

func NewAntiHijackingInterceptor() Interceptor

func NewAuthInterceptor

func NewAuthInterceptor(config AuthConfig) Interceptor

func NewBufferResponseInterceptor added in v7.21.0

func NewBufferResponseInterceptor() 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 SimpleRetryConfig) Interceptor

func NewUpTokenInterceptor added in v7.22.0

func NewUpTokenInterceptor(config UpTokenConfig) Interceptor

type InterceptorPriority

type InterceptorPriority int
const (
	InterceptorPriorityDefault        InterceptorPriority = 100
	InterceptorPriorityRetryHosts     InterceptorPriority = 200
	InterceptorPriorityRetrySimple    InterceptorPriority = 300
	InterceptorPriorityUplog          InterceptorPriority = 310
	InterceptorPriorityBufferResponse InterceptorPriority = 320
	InterceptorPrioritySetHeader      InterceptorPriority = 400
	InterceptorPriorityNormal         InterceptorPriority = 500
	InterceptorPriorityAuth           InterceptorPriority = 600
	InterceptorPriorityAntiHijacking  InterceptorPriority = 700
	InterceptorPriorityDebug          InterceptorPriority = 800
)

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, contentType string, stream compatible_io.ReadSeekCloser) *MultipartForm

func (*MultipartForm) SetValue added in v7.20.0

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

type RequestBodyProgress added in v7.22.0

type RequestBodyProgress func(uint64, uint64)

type RequestParams

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

type RetryConfig

type RetryConfig struct {
	RetryMax      int                  // 最大重试次数
	RetryInterval func() time.Duration // 重试时间间隔 v1
	Backoff       backoff.Backoff      // 重试时间间隔 v2,优先级高于 RetryInterval
	ShouldRetry   func(req *http.Request, resp *http.Response, err error) bool
	Retrier       retrier.Retrier // 重试器
}

type SimpleRetryConfig added in v7.21.0

type SimpleRetryConfig struct {
	RetryMax      int                  // 最大重试次数
	RetryInterval func() time.Duration // 重试时间间隔 v1
	Backoff       backoff.Backoff      // 重试时间间隔 v2,优先级高于 RetryInterval
	ShouldRetry   func(req *http.Request, resp *http.Response, err error) bool
	Resolver      resolver.Resolver // 主备域名解析器
	Chooser       chooser.Chooser   // IP 选择器
	Retrier       retrier.Retrier   // 重试器

	BeforeResolve func(*http.Request)                                         // 域名解析前回调函数
	AfterResolve  func(*http.Request, []net.IP)                               // 域名解析后回调函数
	ResolveError  func(*http.Request, error)                                  // 域名解析错误回调函数
	BeforeBackoff func(*http.Request, *retrier.RetrierOptions, time.Duration) // 退避前回调函数
	AfterBackoff  func(*http.Request, *retrier.RetrierOptions, time.Duration) // 退避后回调函数
	BeforeRequest func(*http.Request, *retrier.RetrierOptions)                // 请求前回调函数
	AfterResponse func(*http.Response, *retrier.RetrierOptions, error)        // 请求后回调函数
}

type UpTokenConfig added in v7.22.0

type UpTokenConfig struct {
	// 上传凭证
	UpToken uptoken.UpTokenProvider
}

Jump to

Keyboard shortcuts

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