Documentation
¶
Index ¶
- Constants
- Variables
- func SetClient(c *Client)
- type AfterFunc
- type Any
- type BeforeFunc
- type BytesReadCloser
- type Client
- func (c *Client) Delete(url string, args ...any) *Request
- func (c *Client) Get(url string, args ...any) *Request
- func (c *Client) Head(url string, args ...any) *Request
- func (c *Client) Options(url string, args ...any) *Request
- func (c *Client) Patch(url string, args ...any) *Request
- func (c *Client) Post(url string, args ...any) *Request
- func (c *Client) Put(url string, args ...any) *Request
- func (c *Client) Request(method string, url string, args ...any) *Request
- type Codec
- type Decoder
- type Encoder
- type Option
- type Request
- func Delete(url string, args ...any) *Request
- func Get(url string, args ...any) *Request
- func Head(url string, args ...any) *Request
- func NewRequest(method string, url string, args ...any) *Request
- func Options(url string, args ...any) *Request
- func Patch(url string, args ...any) *Request
- func Post(url string, args ...any) *Request
- func Put(url string, args ...any) *Request
- func (c *Request) Debug() *Request
- func (c *Request) Send(body any) *Response
- func (c *Request) SetAfter(f AfterFunc) *Request
- func (c *Request) SetBefore(f BeforeFunc) *Request
- func (c *Request) SetContext(ctx context.Context) *Request
- func (c *Request) SetEncoder(encoder Encoder) *Request
- func (c *Request) SetHeader(k, v string) *Request
- func (c *Request) SetHeaders(headers http.Header) *Request
- func (c *Request) SetQuery(query any) *Request
- type Response
- func (c *Response) Bind(v any, decoder Decoder) error
- func (c *Response) BindForm(v *url.Values) error
- func (c *Response) BindJSON(v any) error
- func (c *Response) BindXML(v any) error
- func (c *Response) Context() context.Context
- func (c *Response) Err() error
- func (c *Response) ReadBody() ([]byte, error)
Constants ¶
const ( MimeJson = "application/json;charset=utf-8" MimeYaml = "application/x-yaml;charset=utf-8" MimeXml = "application/xml;charset=utf-8" MimeProtoBuf = "application/x-protobuf" MimeForm = "application/x-www-form-urlencoded" MimeStream = "application/octet-stream" MimeJpeg = "image/jpeg" MimeGif = "image/gif" MimePng = "image/png" MimeMp4 = "video/mpeg4" )
Variables ¶
var ( JsonCodec = new(jsonCodec) FormCodec = new(formCodec) XmlCodec = new(xmlCodec) )
Functions ¶
Types ¶
type BeforeFunc ¶ added in v1.5.0
type BytesReadCloser ¶ added in v1.6.6
type BytesReadCloser interface { io.ReadCloser Bytes() []byte }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
type Encoder ¶ added in v1.3.0
func NewStreamEncoder ¶ added in v1.6.1
type Option ¶ added in v1.5.0
type Option func(c *config)
func WithBefore ¶ added in v1.5.0
func WithBefore(fn BeforeFunc) Option
WithBefore 设置请求前中间件 Setting up pre-request middleware
func WithHTTPClient ¶ added in v1.6.0
WithHTTPClient 设置HTTP客户端 Setting the HTTP client
func WithReuseBody ¶ added in v1.6.6
func WithReuseBody() Option
WithReuseBody 开启Body可重复读; Response.Body可以被断言为BytesReadCloser, 调用Bytes()方法重复读取. Turn on Body repeatable read; Response.Body can be asserted as BytesReadCloser, call Bytes() method to repeat reads.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRequest ¶ added in v1.0.3
NewRequest 新建一个请求 Create a new request
func (*Request) Debug ¶ added in v1.6.4
Debug 开启调试模式, 打印CURL命令 Enable debug mode, print CURL commands
func (*Request) SetBefore ¶ added in v1.6.2
func (c *Request) SetBefore(f BeforeFunc) *Request
SetBefore 设置请求前中间件 Setting up pre-request middleware
func (*Request) SetContext ¶ added in v1.4.0
SetContext 设置请求上下文 Set Request context
func (*Request) SetEncoder ¶ added in v1.3.0
SetEncoder 设置编码器 Set request body encoder
func (*Request) SetHeaders ¶ added in v1.2.0
SetHeaders 批量设置请求头 Set Request Header
func (*Request) SetQuery ¶ added in v1.4.0
SetQuery 设置查询参数, 详情请参考 https://github.com/go-playground/form To set the query parameters, please refer to https://github.com/go-playground/form for details.