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 Crawl(url string, caches ...bool) (string, error)
- func CrawlPage(url string) (string, error)
- func GET(url string) (string, error)
- func Get(ctx context.Context, url string) string
- func GetUserAgent() string
- 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, }, } UserAgents = []string{ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59", } )
...
Functions ¶
func BuildFormData ¶ added in v0.0.6
BuildFormData ...
func BuildReader ¶ added in v0.0.6
BuildReader ...
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.