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 JSON MIME类型 // JSON MIME type MimeJson = "application/json;charset=utf-8" // MimeYaml YAML MIME类型 // YAML MIME type MimeYaml = "application/x-yaml;charset=utf-8" // MimeXml XML MIME类型 // XML MIME type MimeXml = "application/xml;charset=utf-8" // MimeProtoBuf Protobuf MIME类型 // Protobuf MIME type MimeProtoBuf = "application/x-protobuf" // MimeForm 表单 MIME类型 // Form MIME type MimeForm = "application/x-www-form-urlencoded" // MimeStream 流式 MIME类型 // Stream MIME type MimeStream = "application/octet-stream" // MimeJpeg JPEG图片 MIME类型 // JPEG image MIME type MimeJpeg = "image/jpeg" // MimeGif GIF图片 MIME类型 // GIF image MIME type MimeGif = "image/gif" // MimePng PNG图片 MIME类型 // PNG image MIME type MimePng = "image/png" // MimeMp4 MP4视频 MIME类型 // MP4 video MIME type MimeMp4 = "video/mpeg4" )
Variables ¶
var ( // JsonCodec JSON编解码器 // JSON codec JsonCodec = new(jsonCodec) // FormCodec 表单编解码器 // Form codec FormCodec = new(formCodec) // XmlCodec XML编解码器 // XML codec XmlCodec = new(xmlCodec) )
Functions ¶
Types ¶
type BeforeFunc ¶ added in v1.5.0
BeforeFunc 请求前中间件函数类型 Pre-request middleware function type
type BytesReadCloser ¶ added in v1.6.6
type BytesReadCloser interface {
io.ReadCloser
Bytes() []byte
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client HTTP客户端 HTTP client
type Codec ¶ added in v1.7.0
Codec 编解码器接口,同时包含编码和解码功能 Codec interface, includes both encoding and decoding functionality
type Encoder ¶ added in v1.3.0
Encoder 编码器接口 Encoder interface
func NewStreamEncoder ¶ added in v1.6.1
NewStreamEncoder 创建流式编码器 Create a stream encoder
type Option ¶ added in v1.5.0
type Option func(c *config)
func WithBaseURL ¶ added in v1.7.2
WithBaseURL 设置基础URL; 所有请求的URL都会与BaseURL拼接 Setting the base URL; all request URLs will be concatenated with the BaseURL
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
}
Request HTTP请求结构体 HTTP request struct
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.
type Response ¶ added in v1.0.3
Response HTTP响应结构体 HTTP response struct
func (*Response) Bind ¶ added in v1.6.3
Bind 使用指定的解码器将响应体绑定到目标对象 Bind response body to target object using specified decoder