Documentation ¶
Index ¶
- Constants
- type Body
- type Config
- type HTTPTimeout
- type HttpClient
- func (h *HttpClient) AddQueries(params ...interface{}) *HttpClient
- func (h *HttpClient) BaseURL(rawUrl string) *HttpClient
- func (h *HttpClient) Delete(pathURL string) *HttpClient
- func (h *HttpClient) Get(pathURL string) *HttpClient
- func (h *HttpClient) Head(pathURL string) *HttpClient
- func (h *HttpClient) New() *HttpClient
- func (h *HttpClient) Options(pathURL string) *HttpClient
- func (h *HttpClient) Patch(pathURL string) *HttpClient
- func (h *HttpClient) Post(pathURL string) *HttpClient
- func (h *HttpClient) Put(pathURL string) *HttpClient
- func (h *HttpClient) Send(receiver ...io.ReadWriter) (statusCode int, err error)
- func (h *HttpClient) SetBasicAuth(username, password string) *HttpClient
- func (h *HttpClient) SetBody(body Body) *HttpClient
- func (h *HttpClient) SetHeader(key, value string) *HttpClient
- type Retry
Constants ¶
const ( GET = "GET" POST = "POST" PUT = "PUT" HEAD = "HEAD" PATCH = "PATCH" DELETE = "DELETE" OPTIONS = "OPTIONS" ContentTypeJson = "application/json" ContentType = "Content-Type" ContentTypeForm = "application/x-www-form-urlencoded" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶
type Body interface {
Encode(receiver io.ReadWriter) (string, error)
}
func NewFileBody ¶
func NewFormBody ¶
func NewFormBody(body interface{}) Body
formBodyProvider encodes a url tagged struct value as Body for requests. See https://godoc.org/github.com/google/go-querystring/query for details.
func NewJsonBody ¶
jsonBodyProvider encodes a JSON tagged struct value as a Body for requests. See https://golang.org/pkg/encoding/json/#MarshalIndent for details.
func NewOriginalBody ¶
bodyOriginal provides the wrapped body value as a Body for requests.
type Config ¶
type Config struct { HTTPTimeout HTTPTimeout // HTTP的超时时间设置 UseProxy bool // 是否使用代理 ProxyHost string // 代理服务器地址 IsAuthProxy bool // 代理服务器是否使用用户认证 ProxyUser string // 代理服务器认证用户名 ProxyPassword string // 代理服务器认证密码 ReUseTCP bool // 为同一地址多次请求复用TCP连接 TLSClientConfig *tls.Config // tls config }
Config configure
type HTTPTimeout ¶
type HTTPTimeout struct { ConnectTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration ResponseHeaderTimeout time.Duration MaxTimeout time.Duration TLSHandshakeTimeout time.Duration }
HTTPTimeout http timeout
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func New ¶
func New(cfg ...Config) *HttpClient
func (*HttpClient) AddQueries ¶
func (h *HttpClient) AddQueries(params ...interface{}) *HttpClient
AddQuery add queries for GET request
func (*HttpClient) BaseURL ¶
func (h *HttpClient) BaseURL(rawUrl string) *HttpClient
func (*HttpClient) Delete ¶
func (h *HttpClient) Delete(pathURL string) *HttpClient
Delete sets the Sling method to DELETE and sets the given pathURL.
func (*HttpClient) Get ¶
func (h *HttpClient) Get(pathURL string) *HttpClient
Get sets the Request method to GET and sets the given pathURL.
func (*HttpClient) Head ¶
func (h *HttpClient) Head(pathURL string) *HttpClient
Head sets the Request method to HEAD and sets the given pathURL.
func (*HttpClient) New ¶
func (h *HttpClient) New() *HttpClient
func (*HttpClient) Options ¶
func (h *HttpClient) Options(pathURL string) *HttpClient
Options sets the Sling method to OPTIONS and sets the given pathURL.
func (*HttpClient) Patch ¶
func (h *HttpClient) Patch(pathURL string) *HttpClient
Patch sets the Request method to PATCH and sets the given pathURL.
func (*HttpClient) Post ¶
func (h *HttpClient) Post(pathURL string) *HttpClient
Post sets the Request method to POST and sets the given pathURL.
func (*HttpClient) Put ¶
func (h *HttpClient) Put(pathURL string) *HttpClient
Put sets the Request method to PUT and sets the given pathURL.
func (*HttpClient) Send ¶
func (h *HttpClient) Send(receiver ...io.ReadWriter) (statusCode int, err error)
func (*HttpClient) SetBasicAuth ¶
func (h *HttpClient) SetBasicAuth(username, password string) *HttpClient
SetBasicAuth sets the Authorization header to use HTTP Basic Authentication with the provided username and password. With HTTP Basic Authentication the provided username and password are not encrypted.
func (*HttpClient) SetBody ¶
func (h *HttpClient) SetBody(body Body) *HttpClient
func (*HttpClient) SetHeader ¶
func (h *HttpClient) SetHeader(key, value string) *HttpClient
SetHeader sets the key, value pair in Headers, replacing existing values associated with key. Header keys are canonicalized.