Documentation ¶
Index ¶
- Constants
- func Do(c Client, options RequestParams) (*http.Response, error)
- func DoAndDecodeJsonResponse(c Client, options RequestParams, ret interface{}) error
- func IsPrintRequest() bool
- func IsPrintRequestBody() bool
- func IsPrintRequestTrace() bool
- func IsPrintResponse() bool
- func IsPrintResponseBody() bool
- func NewRequest(options RequestParams) (req *http.Request, err error)
- func PrintRequest(level DebugLevel)
- func PrintRequestTrace(isPrint bool)
- func PrintResponse(level DebugLevel)
- func WithInterceptors(req *http.Request, interceptors ...Interceptor) *http.Request
- type AuthConfig
- type Client
- type DebugLevel
- type GetRequestBody
- type Handler
- type HostsRetryConfig
- type Interceptor
- func NewAntiHijackingInterceptor() Interceptor
- func NewAuthInterceptor(config AuthConfig) Interceptor
- func NewBufferResponseInterceptor() Interceptor
- func NewHostsRetryInterceptor(options HostsRetryConfig) Interceptor
- func NewSimpleInterceptor(...) Interceptor
- func NewSimpleInterceptorWithPriority(priority InterceptorPriority, ...) Interceptor
- func NewSimpleRetryInterceptor(config SimpleRetryConfig) Interceptor
- func NewUpTokenInterceptor(config UpTokenConfig) Interceptor
- type InterceptorPriority
- type MultipartForm
- type RequestBodyProgress
- type RequestParams
- type RetryConfig
- type SimpleRetryConfig
- type UpTokenConfig
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 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 Client ¶
func NewClient ¶
func NewClient(cli Client, interceptors ...Interceptor) Client
func NewClientWithClientV1 ¶ added in v7.17.1
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 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 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 RequestParams ¶
type RequestParams struct { Context context.Context Method string Url string Header http.Header GetBody GetRequestBody BufferResponse bool OnRequestProgress RequestBodyProgress }
type RetryConfig ¶
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 }
Source Files ¶
- client.go
- context.go
- interceptor.go
- interceptor_anti_hijacking.go
- interceptor_auth.go
- interceptor_buffer_response.go
- interceptor_debug.go
- interceptor_default_header.go
- interceptor_retry_hosts.go
- interceptor_retry_simple.go
- interceptor_uptoken.go
- multipart.go
- request.go
- request_compatible.go
- retry_config.go
Click to show internal directories.
Click to hide internal directories.