Documentation ¶
Index ¶
- Constants
- func FormatURLParam(body map[string]interface{}) (urlParam string)
- func WithHttpDoer(doer HttpDoer) func(client *Client)
- type Client
- func (c *Client) Delete(url string) (client *Client)
- func (c *Client) EndBytes(ctx context.Context) (res *http.Response, bs []byte, err error)
- func (c *Client) EndStruct(ctx context.Context, v interface{}) (res *http.Response, err error)
- func (c *Client) Get(url string) (client *Client)
- func (c *Client) Patch(url string) (client *Client)
- func (c *Client) Post(url string) (client *Client)
- func (c *Client) Put(url string) (client *Client)
- func (c *Client) SendBodyMap(bm map[string]interface{}) (client *Client)
- func (c *Client) SendMultipartBodyMap(bm map[string]interface{}) (client *Client)
- func (c *Client) SendString(encodeStr string) (client *Client)
- func (c *Client) SendStruct(v interface{}) (client *Client)
- func (c *Client) SetHost(host string) (client *Client)
- func (c *Client) SetTLSConfig(tlsCfg *tls.Config) (client *Client)
- func (c *Client) SetTimeout(timeout time.Duration) (client *Client)
- func (c *Client) SetTransport(transport *http.Transport) (client *Client)
- func (c *Client) Type(typeStr RequestType) (client *Client)
- type HttpDoer
- type RequestType
Constants ¶
View Source
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" PATCH = "PATCH" TypeJSON RequestType = "json" TypeXML RequestType = "xml" TypeUrlencoded RequestType = "urlencoded" TypeForm RequestType = "form" TypeFormData RequestType = "form-data" TypeMultipartFormData RequestType = "multipart-form-data" )
Variables ¶
This section is empty.
Functions ¶
func FormatURLParam ¶ added in v1.5.47
func WithHttpDoer ¶ added in v1.5.63
WithHttpDoer 如果用户不想使用 DefaultHttpClient, 使用该方法即可
Types ¶
type Client ¶
type Client struct { Header http.Header Transport *http.Transport Timeout time.Duration Host string FormString string ContentType string // contains filtered or unexported fields }
func (*Client) SendBodyMap ¶
func (*Client) SendMultipartBodyMap ¶
func (*Client) SendString ¶
SendString encodeStr: url.Values.Encode() or jsonBody
func (*Client) SendStruct ¶
func (*Client) SetTLSConfig ¶
SetTLSConfig 仅在 DefaultHttpClient 为标准 *http.Client 时可生效
func (*Client) SetTimeout ¶
SetTimeout 仅在 DefaultHttpClient 为标准 *http.Client 时可生效
func (*Client) SetTransport ¶ added in v1.5.52
SetTransport 仅在 DefaultHttpClient 为标准 *http.Client 时可生效
func (*Client) Type ¶
func (c *Client) Type(typeStr RequestType) (client *Client)
type HttpDoer ¶ added in v1.5.63
HttpDoer modules a upstream http client.
var DefaultHttpClient HttpDoer = &http.Client{ Timeout: 60 * time.Second, Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, DisableKeepAlives: true, Proxy: http.ProxyFromEnvironment, }, }
DefaultHttpClient 默认为标准 *http.Client, default tls.Config{InsecureSkipVerify: true} 如果使用者实现了自己的 HttpDoer, 请注意参考以下设置
type RequestType ¶
type RequestType string
Click to show internal directories.
Click to hide internal directories.