request

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

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) GetContentLength added in v0.0.3

func (instance NopRSCloser) GetContentLength() int64

GetContentLength 获取数据流大小

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 WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint 使用同一的请求Endpoint

func WithHeader

func WithHeader(header http.Header) Option

WithHeader 设置请求Header

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) 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