request

package
v0.0.0-...-746aa3e Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlackHole

func BlackHole(r io.Reader)

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

func RemoteCallback

func RemoteCallback(url string, body serializer.UploadCallback) error

RemoteCallback 发送远程存储策略上传回调请求

Types

type Client

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

Client 请求客户端

var GeneralClient Client = HTTPClient{}

GeneralClient 通用 HTTP Client

type HTTPClient

type HTTPClient struct {
}

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 WithHeader

func WithHeader(header http.Header) Option

WithHeader 设置请求Header

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 检查响应并获取响应正文

Jump to

Keyboard shortcuts

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