http_client

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: 21 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRegion              = errors.New("no region from provider")
	ErrNoEndpointsConfigured = errors.New("no endpoints configured")
)

Functions

func DefaultBucketHosts

func DefaultBucketHosts() region.Endpoints

DefaultBucketHosts 默认的 Bucket 域名列表

func WithoutSignature added in v7.22.0

func WithoutSignature(ctx context.Context) context.Context

Types

type BasicHTTPClient

type BasicHTTPClient = clientv2.Client

type Client

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

Client 提供了对七牛 HTTP 客户端

func NewClient

func NewClient(options *Options) *Client

NewClient 用来构建一个新的七牛 HTTP 客户端

func (*Client) AccelerateUploadingEnabled added in v7.23.0

func (httpClient *Client) AccelerateUploadingEnabled() bool

func (*Client) Do

func (httpClient *Client) Do(ctx context.Context, request *Request) (*http.Response, error)

Do 发送 HTTP 请求

func (*Client) DoAndAcceptJSON

func (httpClient *Client) DoAndAcceptJSON(ctx context.Context, request *Request, ret interface{}) error

DoAndAcceptJSON 发送 HTTP 请求并接收 JSON 响应

func (*Client) GetAfterBackoffCallback added in v7.22.0

func (httpClient *Client) GetAfterBackoffCallback() func(*http.Request, *retrier.RetrierOptions, time.Duration)

func (*Client) GetAfterResolveCallback added in v7.22.0

func (httpClient *Client) GetAfterResolveCallback() func(*http.Request, []net.IP)

func (*Client) GetAfterResponseCallback added in v7.22.0

func (httpClient *Client) GetAfterResponseCallback() func(*http.Response, *retrier.RetrierOptions, error)

func (*Client) GetAfterSignCallback added in v7.23.0

func (httpClient *Client) GetAfterSignCallback() func(*http.Request)

func (*Client) GetAllRegions added in v7.23.0

func (httpClient *Client) GetAllRegions() region.RegionsProvider

func (*Client) GetBeforeBackoffCallback added in v7.22.0

func (httpClient *Client) GetBeforeBackoffCallback() func(*http.Request, *retrier.RetrierOptions, time.Duration)

func (*Client) GetBeforeRequestCallback added in v7.22.0

func (httpClient *Client) GetBeforeRequestCallback() func(*http.Request, *retrier.RetrierOptions)

func (*Client) GetBeforeResolveCallback added in v7.22.0

func (httpClient *Client) GetBeforeResolveCallback() func(*http.Request)

func (*Client) GetBeforeSignCallback added in v7.23.0

func (httpClient *Client) GetBeforeSignCallback() func(*http.Request)

func (*Client) GetBucketQuery

func (httpClient *Client) GetBucketQuery() region.BucketRegionsQuery

func (*Client) GetChooser added in v7.22.0

func (httpClient *Client) GetChooser() chooser.Chooser

func (*Client) GetClient

func (httpClient *Client) GetClient() BasicHTTPClient

func (*Client) GetCredentials

func (httpClient *Client) GetCredentials() credentials.CredentialsProvider

func (*Client) GetHostFreezeDuration

func (httpClient *Client) GetHostFreezeDuration() time.Duration

func (*Client) GetHostRetryConfig

func (httpClient *Client) GetHostRetryConfig() *RetryConfig

func (*Client) GetHostsRetryConfig

func (httpClient *Client) GetHostsRetryConfig() *RetryConfig

func (*Client) GetRegions

func (httpClient *Client) GetRegions() region.RegionsProvider

func (*Client) GetResolveErrorCallback added in v7.22.0

func (httpClient *Client) GetResolveErrorCallback() func(*http.Request, error)

func (*Client) GetResolver added in v7.22.0

func (httpClient *Client) GetResolver() resolver.Resolver

func (*Client) GetSignErrorCallback added in v7.23.0

func (httpClient *Client) GetSignErrorCallback() func(*http.Request, error)

func (*Client) UseInsecureProtocol

func (httpClient *Client) UseInsecureProtocol() bool

type GetRequestBody

type GetRequestBody = clientv2.GetRequestBody

func GetFormRequestBody

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

GetFormRequestBody 将数据通过 Form 作为请求 Body 发送

func GetJsonRequestBody

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

GetJsonRequestBody 将数据通过 JSON 作为请求 Body 发送

func GetMultipartFormRequestBody

func GetMultipartFormRequestBody(info *MultipartForm) GetRequestBody

GetMultipartFormRequestBody 将数据通过 Multipart 表单作为请求 Body 发送

func GetRequestBodyFromReadSeekCloser

func GetRequestBodyFromReadSeekCloser(r compatible_io.ReadSeekCloser) GetRequestBody

GetMultipartFormRequestBody 将二进制数据请求 Body 发送

type Handler

type Handler = clientv2.Handler

type Interceptor

type Interceptor = clientv2.Interceptor

type InterceptorPriority

type InterceptorPriority = clientv2.InterceptorPriority

type MultipartForm

type MultipartForm = clientv2.MultipartForm

MultipartForm 用来构建 Multipart 表单

type MultipartFormBinaryData

type MultipartFormBinaryData struct {
	Data        compatible_io.ReadSeekCloser
	Name        string
	ContentType string
}

type Options

type Options struct {
	// 基础 HTTP 客户端
	BasicHTTPClient BasicHTTPClient

	// 空间区域查询器
	BucketQuery region.BucketRegionsQuery

	// 所有区域提供者
	AllRegions region.RegionsProvider

	// 区域提供者
	Regions region.RegionsProvider

	// 凭证信息提供者
	Credentials credentials.CredentialsProvider

	// 拦截器
	Interceptors []Interceptor

	// 是否使用 HTTP 协议
	UseInsecureProtocol bool

	// 域名解析器
	Resolver resolver.Resolver

	// 域名选择器
	Chooser chooser.Chooser

	// 单域名重试配置
	HostRetryConfig *RetryConfig

	// 主备域名重试配置
	HostsRetryConfig *RetryConfig

	// 主备域名冻结时间
	HostFreezeDuration time.Duration

	// 主备域名冻结判断函数
	ShouldFreezeHost func(*http.Request, *http.Response, error) bool

	// 签名前回调函数
	BeforeSign func(*http.Request)

	// 签名后回调函数
	AfterSign func(*http.Request)

	// 签名错误回调函数
	SignError func(*http.Request, error)

	// 域名解析前回调函数
	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)

	// 是否加速上传
	AccelerateUploading bool
}

Options 为构建 Client 提供了可选参数

func (*Options) SetBucketHosts

func (options *Options) SetBucketHosts(bucketHosts region.Endpoints) (err error)

type Request

type Request struct {
	// 请求方法
	Method string

	// 请求服务名
	ServiceNames []region.ServiceName

	// 服务地址提供者
	Endpoints region.EndpointsProvider

	// 区域提供者
	Region region.RegionsProvider

	// 请求路径
	Path string

	// 原始请求查询参数
	RawQuery string

	// 请求查询参数
	Query url.Values

	// 请求头
	Header http.Header

	// 请求 Body 获取函数
	RequestBody GetRequestBody

	// 凭证信息提供者
	Credentials credentials.CredentialsProvider

	// 授权类型
	AuthType auth.TokenType

	// 上传凭证接口
	UpToken uptoken.UpTokenProvider

	// 是否缓存响应
	BufferResponse bool

	// 拦截器追加列表
	Interceptors []Interceptor

	// 请求进度回调函数
	OnRequestProgress func(uint64, uint64)
}

Request 包含一个具体的 HTTP 请求的参数

type RetryConfig

type RetryConfig = clientv2.RetryConfig

Jump to

Keyboard shortcuts

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