request

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlackHole

func BlackHole(r io.Reader)

BlackHole 将客户端发来的数据放入黑洞

Types

type Client

type Client interface {
	Request(method, target string, body io.Reader, opts ...Option) *Response
}

Client 请求客户端

var GeneralClient Client = NewClient()

GeneralClient 通用 HTTP Client

func NewClient

func NewClient(opts ...Option) Client

type HTTPClient

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

HTTPClient 实现 Client 接口

func (*HTTPClient) Request

func (c *HTTPClient) Request(method, target string, body io.Reader, opts ...Option) *Response

Request 发送HTTP请求

type NopRSCloser

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

NopRSCloser 实现不完整seeker

func (NopRSCloser) Close

func (instance NopRSCloser) Close() error

Close 实现 NopRSCloser closer

func (NopRSCloser) Read

func (instance NopRSCloser) Read(p []byte) (n int, err error)

Read 实现 NopRSCloser reader

func (NopRSCloser) Seek

func (instance NopRSCloser) Seek(offset int64, whence int) (int64, error)

Seek 实现 NopRSCloser seeker, 只实现seek开头/结尾以便http.ServeContent用于确定正文大小

func (NopRSCloser) SetContentLength

func (instance NopRSCloser) SetContentLength(size int64)

SetContentLength 设置数据流大小

func (NopRSCloser) SetFirstFakeChunk

func (instance NopRSCloser) SetFirstFakeChunk()

SetFirstFakeChunk 开启第一次read返回空数据 TODO 测试

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option 发送请求的额外设置

func WithContentLength

func WithContentLength(s int64) Option

WithContentLength 设置请求大小

func WithContext

func WithContext(c context.Context) Option

WithContext 设置请求上下文

func WithCredential

func WithCredential(instance auth.Auth, ttl int64) Option

WithCredential 对请求进行签名

func WithEndpoint

func WithEndpoint(endpoint string) Option

Endpoint 使用同一的请求Endpoint

func WithHeader

func WithHeader(header http.Header) Option

WithHeader 设置请求Header

func WithMasterMeta

func WithMasterMeta() Option

WithMasterMeta 请求时携带主机信息

func WithSlaveMeta

func WithSlaveMeta(s string) Option

WithSlaveMeta 请求时携带从机信息

func WithTPSLimit

func WithTPSLimit(token string, tps float64, burst int) Option

WithTPSLimit 请求时使用全局流量限制

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout 设置请求超时

func WithoutHeader

func WithoutHeader(header []string) Option

WithoutHeader 设置清除请求Header

type Response

type Response struct {
	Err      error
	Response *http.Response
}

Response 请求的响应或错误信息

func (*Response) CheckHTTPResponse

func (resp *Response) CheckHTTPResponse(status int) *Response

CheckHTTPResponse 检查请求响应HTTP状态码

func (*Response) DecodeResponse

func (resp *Response) DecodeResponse() (*serializer.Response, error)

DecodeResponse 尝试解析为serializer.Response,并对状态码进行检查

func (*Response) GetRSCloser

func (resp *Response) GetRSCloser() (*NopRSCloser, error)

GetRSCloser 返回带有空seeker的RSCloser,供http.ServeContent使用

func (*Response) GetResponse

func (resp *Response) GetResponse() (string, error)

GetResponse 检查响应并获取响应正文

type TPSLimiter

type TPSLimiter interface {
	Limit(ctx context.Context, token string, tps float64, burst int)
}

func NewTPSLimiter

func NewTPSLimiter() TPSLimiter

Jump to

Keyboard shortcuts

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