Documentation ¶
Index ¶
- Constants
- Variables
- func NewGoCurl() *goCurl
- type Request
- func (r *Request) DisableCloseConn() *Request
- func (r *Request) DisableTrace() *Request
- func (r *Request) DumpAll() string
- func (r *Request) DumpRequest() string
- func (r *Request) DumpResponse() string
- func (r *Request) EnableCloseConn() *Request
- func (r *Request) EnableTrace() *Request
- func (r *Request) Get() (*Response, error)
- func (r *Request) Post() (*Response, error)
- func (r *Request) Send() (*Response, error)
- func (r *Request) SetBody(body interface{}) *Request
- func (r *Request) SetContentType(contentType string) *Request
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetCookie(key, value string) *Request
- func (r *Request) SetCookies(cookies map[string]string) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaders(headers map[string]string) *Request
- func (r *Request) SetMethod(method string) *Request
- func (r *Request) SetPostData(data map[string]interface{}) *Request
- func (r *Request) SetQueries(queries map[string]string) *Request
- func (r *Request) SetQuery(key, value string) *Request
- func (r *Request) SetTimeOut(timeout time.Duration) *Request
- func (r *Request) SetUrl(url string) *Request
- func (r *Request) TraceInfo() TraceInfo
- type Response
- func (r *Response) GetContentType() string
- func (r *Response) GetHeader(key string) string
- func (r *Response) GetHeaderValues(key string) []string
- func (r *Response) HeaderToString() string
- func (r *Response) IsOk() bool
- func (r *Response) ReceivedAt() time.Time
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) TotalTime() time.Duration
- func (r *Response) TraceInfo() TraceInfo
- type TraceInfo
Constants ¶
const ( ClientTimeout = 15 * time.Second JsonContentType = "application/json" JsonUTF8ContentType = "application/json;charset=utf-8" FormUrlEncodedContentType = "application/x-www-form-urlencoded" )
Variables ¶
var Client = (func() *http.Client { t := http.DefaultTransport.(*http.Transport).Clone() t.MaxIdleConns = 100 t.MaxConnsPerHost = 100 t.MaxIdleConnsPerHost = 100 return &http.Client{Transport: t, Timeout: ClientTimeout} })()
Client Customize http.Client to optimize the performance based on the original http.DefaultTransport @see https://www.loginradius.com/blog/async/tune-the-go-http-client-for-high-performance
Functions ¶
Types ¶
type Request ¶
type Request struct { Url string Method string Timeout time.Duration Headers map[string]string Cookies map[string]string Queries map[string]string PostData map[string]interface{} Body io.Reader Response *Response // contains filtered or unexported fields }
func (*Request) DisableCloseConn ¶ added in v1.3.0
DisableCloseConn disable close connection
func (*Request) DisableTrace ¶ added in v1.3.0
DisableTrace disables trace.
func (*Request) DumpRequest ¶ added in v1.3.0
func (*Request) DumpResponse ¶ added in v1.3.0
func (*Request) EnableCloseConn ¶ added in v1.3.0
EnableCloseConn closes the connection after sending this request and reading its response if set to true in HTTP/1.1 and HTTP/2. Setting this field prevents re-use of TCP connections between requests to the same hosts event if EnableKeepAlives() were called.
func (*Request) EnableTrace ¶ added in v1.3.0
EnableTrace enables trace (http3 currently does not support trace).
func (*Request) SetBody ¶
SetBody set the request Body, accepts string, []byte, io.Reader, io.ReadCloser.
func (*Request) SetContentType ¶ added in v1.3.0
SetContentType set the `Content-Type` for the request.
func (*Request) SetContext ¶ added in v1.3.0
SetContext method sets the context.Context for current Request. It allows to interrupt the request execution if ctx.Done() channel is closed. See https://blog.golang.org/context article and the "context" package documentation.
func (*Request) SetCookies ¶
SetCookies set request cookies
func (*Request) SetHeaders ¶
SetHeaders set request headers
func (*Request) SetPostData ¶
SetPostData set post data
func (*Request) SetQueries ¶
SetQueries set request query
func (*Request) SetTimeOut ¶
SetTimeOut set request timeout after
type Response ¶
type Response struct { Raw *http.Response Request *Request Body string // contains filtered or unexported fields }
func (*Response) GetContentType ¶ added in v1.3.0
GetContentType return the `Content-Type` header value.
func (*Response) GetHeaderValues ¶ added in v1.3.0
GetHeaderValues returns the response header values by key.
func (*Response) HeaderToString ¶ added in v1.3.0
HeaderToString get all header as string.
func (*Response) ReceivedAt ¶ added in v1.3.0
ReceivedAt returns the timestamp that response we received.
func (*Response) StatusCode ¶
StatusCode returns the response status code.
type TraceInfo ¶ added in v1.3.0
type TraceInfo struct { // DNSLookupTime is a duration that transport took to perform // DNS lookup. DNSLookupTime time.Duration // ConnectTime is a duration that took to obtain a successful connection. ConnectTime time.Duration // TCPConnectTime is a duration that took to obtain the TCP connection. TCPConnectTime time.Duration // TLSHandshakeTime is a duration that TLS handshake took place. TLSHandshakeTime time.Duration // FirstResponseTime is a duration that server took to respond first byte since // connection ready (after tls handshake if it's tls and not a reused connection). FirstResponseTime time.Duration // ResponseTime is a duration since first response byte from server to // request completion. ResponseTime time.Duration // TotalTime is a duration that total request took end-to-end. TotalTime time.Duration // IsConnReused is whether this connection has been previously // used for another HTTP request. IsConnReused bool // IsConnWasIdle is whether this connection was obtained from an // idle pool. IsConnWasIdle bool // ConnIdleTime is a duration how long the connection was previously // idle, if IsConnWasIdle is true. ConnIdleTime time.Duration // LocalAddr returns the local network address. LocalAddr net.Addr // RemoteAddr returns the remote network address. RemoteAddr net.Addr }
TraceInfo represents the trace information.