v2

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IRequest

type IRequest interface {
	WithURL(url string) IRequest
	WithMethod(method string) IRequest
	WithData(data io.Reader) IRequest
	WithForm(form url.Values) IRequest
	WithProxy(url string) IRequest
	WithCookies(cookies []*http.Cookie) IRequest
	WithHeaders(headers map[string]string) IRequest
	Send(callBack func(resp IResponse, err error))
}

IRequest 接口,定义请求的行为

func NewRequest

func NewRequest(options ...Option) IRequest

NewRequest 支持两种方式构造请求

type IResponse

type IResponse interface {
	StatusCode() int
	Json() *gjson.Result
	Text() string
	Bytes() []byte
	RaiseCode(code int) error
	WriteFile(fileName, perm, dir string) error
	WriteJson(fileName, perm, dir string) error
}

IResponse 接口,定义响应的行为

type Option

type Option func(*Request)

Option 类型,表示可变参数的配置函数

func WithData

func WithData(data io.Reader) Option

func WithForm

func WithForm(form url.Values) Option

func WithMethod

func WithMethod(method string) Option

Option 函数实现,支持可变参数调用

func WithProxy

func WithProxy(uri string) Option

func WithURL

func WithURL(url string) Option

type Request

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

Request 实现 IRequest 接口

func (*Request) Send

func (r *Request) Send(callBack func(resp IResponse, err error))

Send 发送请求

func (*Request) WithCookies

func (r *Request) WithCookies(cookies []*http.Cookie) IRequest

WithCookies 配置 cookies 为链式调用

func (*Request) WithData

func (r *Request) WithData(data io.Reader) IRequest

WithData 配置数据为链式调用

func (*Request) WithForm

func (r *Request) WithForm(form url.Values) IRequest

WithForm 配置表单数据为链式调用

func (*Request) WithHeaders

func (r *Request) WithHeaders(headers map[string]string) IRequest

WithHeaders 配置 headers 为链式调用

func (*Request) WithMethod

func (r *Request) WithMethod(method string) IRequest

WithMethod 配置方法为链式调用

func (*Request) WithProxy

func (r *Request) WithProxy(uri string) IRequest

WithProxy 配置方法为链式调用

func (*Request) WithURL

func (r *Request) WithURL(url string) IRequest

WithURL 配置 URL 为链式调用

type Response

type Response struct {
	Resp *http.Response
	Body []byte
}

Response 实现 IResponse 接口

func (*Response) Bytes

func (r *Response) Bytes() []byte

func (*Response) Json

func (r *Response) Json() *gjson.Result

func (*Response) RaiseCode

func (r *Response) RaiseCode(code int) error

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) Text

func (r *Response) Text() string

func (*Response) WriteFile

func (r *Response) WriteFile(fileName, perm, dir string) error

func (*Response) WriteJson

func (r *Response) WriteJson(fileName, perm, dir string) error

Jump to

Keyboard shortcuts

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