clientv2

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestMethodGet    = "GET"
	RequestMethodPut    = "PUT"
	RequestMethodPost   = "POST"
	RequestMethodHead   = "HEAD"
	RequestMethodDelete = "DELETE"
)

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{}) (*http.Response, error)

func FormStringInfo

func FormStringInfo(info map[string][]string) string

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) (*http.Request, error)

func PrintRequest

func PrintRequest(level DebugLevel)

func PrintRequestTrace

func PrintRequestTrace(isPrint bool)

func PrintResponse

func PrintResponse(level DebugLevel)

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

func NewClientWithClientV1(c *clientV1.Client) Client

type DebugLevel

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

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 RequestBodyCreator

type RequestBodyCreator func(options *RequestParams) (io.Reader, error)

func RequestBodyCreatorForm

func RequestBodyCreatorForm(info map[string][]string) RequestBodyCreator

func RequestBodyCreatorOfJson

func RequestBodyCreatorOfJson(object interface{}) RequestBodyCreator

type RequestParams

type RequestParams struct {
	Context     context.Context
	Method      string
	Url         string
	Header      http.Header
	BodyCreator RequestBodyCreator
}

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