Documentation
¶
Index ¶
- Constants
- Variables
- func BuildFormData(header http.Header, m map[string]interface{}) (http.Header, io.Reader)
- func BuildReader(data interface{}, types ...string) io.Reader
- func BuildURL(url string, m map[string]interface{}) string
- func BuildValues(m map[string]interface{}) url.Values
- func Get(ctx context.Context, url string) string
- func ParseQuery(str string) map[string]string
- func ParseURL(str string) (*url.URL, error)
- func Post(ctx context.Context, url string, data interface{}) string
- func ToResponse(r *Response, err error) (*http.Response, error)
- func ToString(r *Response, err error) string
- type Client
- func (t *Client) Delete(ctx context.Context, url string, header http.Header) (*Response, error)
- func (t *Client) Do(ctx context.Context, method string, url string, header http.Header, ...) (*Response, error)
- func (t *Client) Get(ctx context.Context, url string, header http.Header) (*Response, error)
- func (t *Client) Patch(ctx context.Context, url string, header http.Header) (*Response, error)
- func (t *Client) Post(ctx context.Context, url string, header http.Header, data interface{}) (*Response, error)
- func (t *Client) Put(ctx context.Context, url string, header http.Header, data interface{}) (*Response, error)
- type Option
- type OptionFn
- type Response
- type Trace
Constants ¶
View Source
const ( MethodGet = "GET" MethodPost = "POST" MethodPut = "PUT" MethodDelete = "DELETE" MethodPatch = "PATCH" MethodHead = "HEAD" MethodOptions = "OPTIONS" )
Method ...
View Source
const ( HeaderKeyUserAgent = "User-Agent" HeaderKeyAccept = "Accept" HeaderKeyContentType = "Content-Type" HeaderKeyContentLength = "Content-Length" HeaderKeyContentEncoding = "Content-Encoding" HeaderKeyLocation = "Location" HeaderKeyAuthorization = "Authorization" HeaderKeyAcceptEncoding = "Accept-Encoding" HeaderKeyContentTypeValueJSON = "application/json" HeaderKeyContentTypeValueForm = "application/x-www-form-urlencoded" HeaderKeyContentTypeValueFormData = "multipart/form-data" HeaderKeyContentEncodingValueGzip = "gzip" )
HeaderKey header 字段, 同 http.CanonicalHeaderKey() 效果一致
Variables ¶
View Source
var ( HeaderContentTypeJSON = http.Header{ HeaderKeyContentType: []string{ HeaderKeyContentTypeValueJSON, }, } HeaderContentTypeForm = http.Header{ HeaderKeyContentType: []string{ HeaderKeyContentTypeValueForm, }, } HeaderContentTypeFormData = http.Header{ HeaderKeyContentType: []string{ HeaderKeyContentTypeValueFormData, }, } )
...
Functions ¶
func BuildFormData ¶ added in v0.0.6
BuildFormData ...
func BuildReader ¶ added in v0.0.6
BuildReader ...
func BuildValues ¶ added in v0.0.6
BuildValues ...
func ToResponse ¶ added in v0.0.6
ToResponse ...
Types ¶
type Client ¶ added in v0.0.5
Client ...
func (*Client) Do ¶ added in v0.0.5
func (t *Client) Do( ctx context.Context, method string, url string, header http.Header, data interface{}, ) (*Response, error)
Do ...
type Option ¶
type Option struct { RetryTimes int // 请求重试次数 TraceEnable bool // Trace 开关 RequestTimeout time.Duration // 请求超时 Dialer *net.Dialer // dialer 配置 Transport *http.Transport // transport 配置 }
Option ...
type OptionFn ¶ added in v0.0.6
type OptionFn func(*Option)
OptionFn ...
func WithRequestTimeout ¶ added in v0.0.6
WithRequestTimeout 请求超时
func WithTraceEnable ¶ added in v0.0.6
func WithTraceEnable() OptionFn
WithTrace 可以通过返回 Response.Trace 查询
func WithTransport ¶ added in v0.0.6
WithTransport ...
type Trace ¶ added in v0.0.6
type Trace struct { DNSLookup time.Duration `json:"dns_lookup"` ConnTime time.Duration `json:"conn_time"` TCPConnTime time.Duration `json:"tcp_conn_time"` TLSHandshake time.Duration `json:"tls_handshake"` ServerTime time.Duration `json:"server_time"` ResponseTime time.Duration `json:"response_time"` TotalTime time.Duration `json:"total_time"` IsConnReused bool `json:"is_conn_reused"` IsConnWasIdle bool `json:"is_conn_was_idle"` ConnIdleTime time.Duration `json:"conn_idle_time"` RequestAttempt int `json:"request_attempt"` RemoteAddr net.Addr `json:"remote_addr"` // contains filtered or unexported fields }
Trace ...
Click to show internal directories.
Click to hide internal directories.