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 ¶
DNSResolver DNS解析
type DialContext ¶
type Option ¶
type Option func(*options)
func WithConnectTimeout ¶
WithConnectTimeout 设置连接超时
func WithCookieJar ¶
func WithDNSResolver ¶
func WithDNSResolver(dnsResolver DNSResolverFunc) Option
func WithEnableDefaultHeader ¶
func WithEnableDefaultHeader() Option
WithEnableDefaultHeader 设置默认header
func WithMaxIdleConnsPerHost ¶
WithMaxIdleConnsPerHost 设置每个host最大空闲连接数
func WithShouldRetryFunc ¶
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.