Documentation
¶
Overview ¶
Package httpclient http客户端
Index ¶
- type DNSResolverFunc
- type DialContext
- type Option
- func WithClient(client *http.Client) Option
- func WithConnectTimeout(timeout time.Duration) Option
- func WithCookieJar(cookieJar http.CookieJar) Option
- func WithDNSResolver(dnsResolver DNSResolverFunc) Option
- func WithDebug() Option
- func WithDisableKeepAlive() Option
- func WithEnableDefaultHeader() Option
- func WithMaxIdleConnsPerHost(n int) Option
- func WithProxyURL(proxyURL string) Option
- func WithRetryTime(retryTimes int) Option
- func WithShouldRetryFunc(f func(*http.Response, error) bool) Option
- func WithTimeout(timeout time.Duration) Option
- type Request
- type Response
- func (resp *Response) Bytes() ([]byte, error)
- func (resp *Response) DecodeJSON(v interface{}) error
- func (resp *Response) Discard() (int64, error)
- func (resp *Response) Header() http.Header
- func (resp *Response) IsStatusOK() bool
- func (resp *Response) Raw() *http.Response
- func (resp *Response) String() (string, error)
- func (resp *Response) WriteFile(filename string) (int64, error)
- func (resp *Response) WriteTo(w io.Writer) (int64, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DNSResolverFunc ¶ added in v1.0.8
DNSResolver DNS解析
type DialContext ¶ added in v1.0.7
type Option ¶ added in v1.0.6
type Option func(*options)
func WithClient ¶ added in v1.0.6
WithClient 自定义http client
func WithConnectTimeout ¶ added in v1.0.9
WithConnectTimeout 设置连接超时
func WithCookieJar ¶ added in v1.1.0
func WithDNSResolver ¶ added in v1.0.7
func WithDNSResolver(dnsResolver DNSResolverFunc) Option
func WithDisableKeepAlive ¶ added in v1.0.6
func WithDisableKeepAlive() Option
WithDisableKeepAlive 连接重用
func WithEnableDefaultHeader ¶ added in v1.0.6
func WithEnableDefaultHeader() Option
WithEnableDefaultHeader 设置默认header
func WithMaxIdleConnsPerHost ¶ added in v1.0.9
WithMaxIdleConnsPerHost 设置每个host最大空闲连接数
func WithShouldRetryFunc ¶ added in v1.0.6
WithShouldRetryFunc 自定义是否需要重试
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request http请求
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response http响应
func (*Response) DecodeJSON ¶
DecodeJSON http.Body json decode
func (*Response) WriteTo ¶
WriteTo 读取http.Body并写入w中
Example ¶
content := []byte("write file") handler := func(rw http.ResponseWriter, req *http.Request) { rw.Write(content) } s := httptest.NewServer(http.HandlerFunc(handler)) defer s.Close() req := NewRequest() resp, err := req.Get(s.URL, nil, nil) if err != nil { panic(err) } _, err = resp.WriteTo(os.Stdout) if err != nil { panic(err) }
Output: write file
Click to show internal directories.
Click to hide internal directories.