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 ¶
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 ¶
type DebugLevel ¶
type DebugLevel int
const ( DebugLevelPrintNone DebugLevel = 0 DebugLevelPrintNormal DebugLevel = 1 DebugLevelPrintDetail DebugLevel = 2 )
type GetRequestBody ¶
type GetRequestBody func(options *RequestParams) (io.ReadCloser, error)
func GetFormRequestBody ¶
func GetFormRequestBody(info map[string][]string) GetRequestBody
func GetJsonRequestBody ¶
func GetJsonRequestBody(object interface{}) (GetRequestBody, error)
func GetMultipartFormRequestBody ¶
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 ¶
func NewAntiHijackingInterceptor() Interceptor
func NewAuthInterceptor ¶
func NewAuthInterceptor(config AuthConfig) Interceptor
func NewBufferResponseInterceptor ¶
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 ¶
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 ¶
type MultipartForm struct {
// contains filtered or unexported fields
}
func (*MultipartForm) SetFile ¶
func (f *MultipartForm) SetFile(key, fileName, contentType string, stream compatible_io.ReadSeekCloser) *MultipartForm
func (*MultipartForm) SetValue ¶
func (f *MultipartForm) SetValue(key, value string) *MultipartForm
type RequestBodyProgress ¶
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 ¶
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 ¶
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.