Documentation ¶
Index ¶
- func LoadKeyCrt(crtFile, keyFile string) (*tls.Config, error)
- type Client
- func (c *Client) BasicAuth(user, pass string) *Client
- func (c *Client) Clone() *Client
- func (c *Client) Connect(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) ConnectBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) ConnectContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) ConnectVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) ContentJson() *Client
- func (c *Client) ContentType(contentType string) *Client
- func (c *Client) ContentXml() *Client
- func (c *Client) Cookie(m map[string]string) *Client
- func (c *Client) Delete(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) DeleteBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) DeleteContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) DeleteVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) DoRequest(ctx context.Context, method, url string, data ...interface{}) (resp *Response, err error)
- func (c *Client) Dump(dump ...bool) *Client
- func (c *Client) Get(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) GetBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) GetContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) GetVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) Head(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) HeadBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) HeadContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) HeadVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) Header(m map[string]string) *Client
- func (c *Client) HeaderRaw(headers string) *Client
- func (c *Client) Next(req *http.Request) (*Response, error)
- func (c *Client) Options(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) OptionsBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) OptionsContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) OptionsVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) Patch(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) PatchBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) PatchContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) PatchVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) Post(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) PostBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) PostContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) PostVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) Prefix(prefix string) *Client
- func (c *Client) Proxy(proxyURL string) *Client
- func (c *Client) Put(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) PutBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) PutContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) PutVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) RedirectLimit(redirectLimit int) *Client
- func (c *Client) RequestBytes(ctx context.Context, method string, url string, data ...interface{}) []byte
- func (c *Client) RequestContent(ctx context.Context, method string, url string, data ...interface{}) string
- func (c *Client) RequestVar(ctx context.Context, method string, url string, data ...interface{}) *gvar.Var
- func (c *Client) Retry(retryCount int, retryInterval time.Duration) *Client
- func (c *Client) SetAgent(agent string) *Client
- func (c *Client) SetBasicAuth(user, pass string) *Client
- func (c *Client) SetBrowserMode(enabled bool) *Client
- func (c *Client) SetContentType(contentType string) *Client
- func (c *Client) SetCookie(key, value string) *Client
- func (c *Client) SetCookieMap(m map[string]string) *Client
- func (c *Client) SetDump(dump bool) *Client
- func (c *Client) SetHeader(key, value string) *Client
- func (c *Client) SetHeaderMap(m map[string]string) *Client
- func (c *Client) SetHeaderRaw(headers string) *Client
- func (c *Client) SetPrefix(prefix string) *Client
- func (c *Client) SetProxy(proxyURL string)
- func (c *Client) SetRedirectLimit(redirectLimit int) *Client
- func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client
- func (c *Client) SetTLSConfig(tlsConfig *tls.Config) error
- func (c *Client) SetTLSKeyCrt(crtFile, keyFile string) error
- func (c *Client) SetTimeout(t time.Duration) *Client
- func (c *Client) Timeout(t time.Duration) *Client
- func (c *Client) Trace(ctx context.Context, url string, data ...interface{}) (*Response, error)
- func (c *Client) TraceBytes(ctx context.Context, url string, data ...interface{}) []byte
- func (c *Client) TraceContent(ctx context.Context, url string, data ...interface{}) string
- func (c *Client) TraceVar(ctx context.Context, url string, data ...interface{}) *gvar.Var
- func (c *Client) Use(handlers ...HandlerFunc) *Client
- type HandlerFunc
- type Response
- func (r *Response) Close() error
- func (r *Response) GetCookie(key string) string
- func (r *Response) GetCookieMap() map[string]string
- func (r *Response) Raw() string
- func (r *Response) RawDump()
- func (r *Response) RawRequest() string
- func (r *Response) RawResponse() string
- func (r *Response) ReadAll() []byte
- func (r *Response) ReadAllString() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct { http.Client // Underlying HTTP Client. // contains filtered or unexported fields }
Client is the HTTP client for HTTP request management.
func (*Client) BasicAuth ¶
BasicAuth is a chaining function, which sets HTTP basic authentication information for next request.
func (*Client) Clone ¶
Clone deeply clones current client and returns a new one.
func (*Client) Connect ¶
Connect send CONNECT request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) ConnectBytes ¶
ConnectBytes sends a CONNECT request, retrieves and returns the result content as bytes.
func (*Client) ConnectContent ¶
ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns the result content and automatically closes response object.
func (*Client) ConnectVar ¶
ConnectVar sends a CONNECT request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) ContentJson ¶
ContentJson is a chaining function, which sets the HTTP content type as "application/json" for the next request.
Note that it also checks and encodes the parameter to JSON format automatically.
func (*Client) ContentType ¶
ContentType is a chaining function, which sets HTTP content type for the next request.
func (*Client) ContentXml ¶
ContentXml is a chaining function, which sets the HTTP content type as "application/xml" for the next request.
Note that it also checks and encodes the parameter to XML format automatically.
func (*Client) Cookie ¶
Cookie is a chaining function, which sets cookie items with map for next request.
func (*Client) Delete ¶
Delete send DELETE request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) DeleteBytes ¶
DeleteBytes sends a DELETE request, retrieves and returns the result content as bytes.
func (*Client) DeleteContent ¶
DeleteContent is a convenience method for sending DELETE request, which retrieves and returns the result content and automatically closes response object.
func (*Client) DeleteVar ¶
DeleteVar sends a DELETE request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) DoRequest ¶
func (c *Client) DoRequest(ctx context.Context, method, url string, data ...interface{}) (resp *Response, err error)
DoRequest sends request with given HTTP method and data and returns the response object. Note that the response object MUST be closed if it'll never be used.
Note that it uses "multipart/form-data" as its Content-Type if it contains file uploading, else it uses "application/x-www-form-urlencoded". It also automatically detects the post content for JSON format, and for that it automatically sets the Content-Type as "application/json".
func (*Client) Dump ¶
Dump is a chaining function, which enables/disables dump feature for this request.
func (*Client) Get ¶
Get send GET request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) GetBytes ¶
GetBytes sends a GET request, retrieves and returns the result content as bytes.
func (*Client) GetContent ¶
GetContent is a convenience method for sending GET request, which retrieves and returns the result content and automatically closes response object.
func (*Client) GetVar ¶
GetVar sends a GET request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Head ¶
Head send HEAD request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) HeadBytes ¶
HeadBytes sends a HEAD request, retrieves and returns the result content as bytes.
func (*Client) HeadContent ¶
HeadContent is a convenience method for sending HEAD request, which retrieves and returns the result content and automatically closes response object.
func (*Client) HeadVar ¶
HeadVar sends a HEAD request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Header ¶
Header is a chaining function, which sets custom HTTP headers with map for next request.
func (*Client) HeaderRaw ¶
HeaderRaw is a chaining function, which sets custom HTTP header using raw string for next request.
func (*Client) Next ¶
Next calls the next middleware. This should only be call in HandlerFunc.
func (*Client) Options ¶
Options send OPTIONS request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) OptionsBytes ¶
OptionsBytes sends a OPTIONS request, retrieves and returns the result content as bytes.
func (*Client) OptionsContent ¶
OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns the result content and automatically closes response object.
func (*Client) OptionsVar ¶
OptionsVar sends a OPTIONS request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Patch ¶
Patch send PATCH request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) PatchBytes ¶
PatchBytes sends a PATCH request, retrieves and returns the result content as bytes.
func (*Client) PatchContent ¶
PatchContent is a convenience method for sending PATCH request, which retrieves and returns the result content and automatically closes response object.
func (*Client) PatchVar ¶
PatchVar sends a PATCH request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Post ¶
Post sends request using HTTP method POST and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) PostBytes ¶
PostBytes sends a POST request, retrieves and returns the result content as bytes.
func (*Client) PostContent ¶
PostContent is a convenience method for sending POST request, which retrieves and returns the result content and automatically closes response object.
func (*Client) PostVar ¶
PostVar sends a POST request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Prefix ¶
Prefix is a chaining function, which sets the URL prefix for next request of this client.
func (*Client) Proxy ¶
Proxy is a chaining function, which sets proxy for next request. Make sure you pass the correct `proxyURL`. The correct pattern is like `http://USER:PASSWORD@IP:PORT` or `socks5://USER:PASSWORD@IP:PORT`. Only `http` and `socks5` proxies are supported currently.
func (*Client) Put ¶
Put send PUT request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) PutBytes ¶
PutBytes sends a PUT request, retrieves and returns the result content as bytes.
func (*Client) PutContent ¶
PutContent is a convenience method for sending PUT request, which retrieves and returns the result content and automatically closes response object.
func (*Client) PutVar ¶
PutVar sends a PUT request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) RedirectLimit ¶
RedirectLimit is a chaining function, which sets the redirect limit the number of jumps for the request.
func (*Client) RequestBytes ¶
func (c *Client) RequestBytes(ctx context.Context, method string, url string, data ...interface{}) []byte
RequestBytes sends request using given HTTP method and data, retrieves returns the result as bytes. It reads and closes the response object internally automatically.
func (*Client) RequestContent ¶
func (c *Client) RequestContent(ctx context.Context, method string, url string, data ...interface{}) string
RequestContent is a convenience method for sending custom http method request, which retrieves and returns the result content and automatically closes response object.
func (*Client) RequestVar ¶
func (c *Client) RequestVar(ctx context.Context, method string, url string, data ...interface{}) *gvar.Var
RequestVar sends request using given HTTP method and data, retrieves converts the result to specified pointer. It reads and closes the response object internally automatically. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Retry ¶
Retry is a chaining function, which sets retry count and interval when failure for next request.
func (*Client) SetAgent ¶
SetAgent sets the User-Agent header for client.
func (*Client) SetBasicAuth ¶
SetBasicAuth sets HTTP basic authentication information for the client.
func (*Client) SetBrowserMode ¶
SetBrowserMode enables browser mode of the client. When browser mode is enabled, it automatically saves and sends cookie content from and to server.
func (*Client) SetContentType ¶
SetContentType sets HTTP content type for the client.
func (*Client) SetCookie ¶
SetCookie sets a cookie pair for the client.
func (*Client) SetCookieMap ¶
SetCookieMap sets cookie items with map.
func (*Client) SetDump ¶
SetDump enables/disables dump feature for this request.
func (*Client) SetHeader ¶
SetHeader sets a custom HTTP header pair for the client.
func (*Client) SetHeaderMap ¶
SetHeaderMap sets custom HTTP headers with map.
func (*Client) SetHeaderRaw ¶
SetHeaderRaw sets custom HTTP header using raw string.
func (*Client) SetPrefix ¶
SetPrefix sets the request server URL prefix.
func (*Client) SetProxy ¶
SetProxy set proxy for the client. This func will do nothing when the parameter `proxyURL` is empty or in wrong pattern. The correct pattern is like `http://USER:PASSWORD@IP:PORT` or `socks5://USER:PASSWORD@IP:PORT`. Only `http` and `socks5` proxies are supported currently.
func (*Client) SetRedirectLimit ¶
SetRedirectLimit limit the number of jumps
func (*Client) SetRetry ¶
SetRetry sets retry count and interval.
func (*Client) SetTLSConfig ¶
SetTLSConfig sets the TLS configuration of client.
func (*Client) SetTLSKeyCrt ¶
SetTLSKeyCrt sets the certificate and key file for TLS configuration of client.
func (*Client) SetTimeout ¶
SetTimeout sets the request timeout for the client.
func (*Client) Timeout ¶
Timeout is a chaining function, which sets the timeout for next request.
func (*Client) Trace ¶
Trace send TRACE request and returns the response object. Note that the response object MUST be closed if it'll never be used.
func (*Client) TraceBytes ¶
TraceBytes sends a TRACE request, retrieves and returns the result content as bytes.
func (*Client) TraceContent ¶
TraceContent is a convenience method for sending TRACE request, which retrieves and returns the result content and automatically closes response object.
func (*Client) TraceVar ¶
TraceVar sends a TRACE request, retrieves and converts the result content to specified pointer. The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (*Client) Use ¶
func (c *Client) Use(handlers ...HandlerFunc) *Client
Use adds one or more middleware handlers to client.
type HandlerFunc ¶
HandlerFunc middleware handler func
type Response ¶
Response is the struct for client request response.
func MiddlewareTracing ¶
MiddlewareTracing is a client middleware that enables tracing feature using standards of OpenTelemetry.
func (*Response) Close ¶
Close closes the response when it will never be used.
func (*Response) GetCookie ¶
GetCookie retrieves and returns the cookie value of specified `key`.
func (*Response) GetCookieMap ¶
GetCookieMap retrieves and returns a copy of current cookie values map.
func (*Response) Raw ¶
Raw returns the raw text of the request and the response.
func (*Response) RawDump ¶
func (r *Response) RawDump()
RawDump outputs the raw text of the request and the response to stdout.
func (*Response) RawRequest ¶
RawRequest returns the raw content of the request.
func (*Response) RawResponse ¶
RawResponse returns the raw content of the response.
func (*Response) ReadAll ¶
ReadAll retrieves and returns the response content as []byte.