Documentation ¶
Overview ¶
Powerful and easy to use http client
Powerful and easy to use http client
Index ¶
- Constants
- Variables
- func IsNil(obj interface{}) bool
- func IsRedirectError(err error) bool
- func IsTimeoutError(err error) bool
- func Md5(s string) string
- func Option(o map[string]interface{}) map[int]interface{}
- type Error
- type HttpClient
- func (client *HttpClient) Begin() *HttpClient
- func (client *HttpClient) Defaults(defaults Map) *HttpClient
- func (client *HttpClient) Delete(url string, params ...interface{}) (*Response, error)
- func (client *HttpClient) Do(method string, url string, headers map[string]string, body io.Reader) (*Response, error)
- func (client *HttpClient) Get(url string, params ...interface{}) (*Response, error)
- func (client *HttpClient) Head(url string) (*Response, error)
- func (client *HttpClient) Post(url string, params interface{}) (*Response, error)
- func (client *HttpClient) PostJson(url string, data interface{}) (*Response, error)
- func (client *HttpClient) PostMultipart(url string, params interface{}) (*Response, error)
- func (client *HttpClient) Put(url string, body io.Reader) (*Response, error)
- func (client *HttpClient) PutJson(url string, data interface{}) (*Response, error)
- func (client *HttpClient) WithCommonHeader(appName, appSecretKey string) *HttpClient
- func (client *HttpClient) WithHeader(k string, v string) *HttpClient
- func (client *HttpClient) WithHeaders(m map[string]string) *HttpClient
- func (client *HttpClient) WithOption(k int, v interface{}) *HttpClient
- func (client *HttpClient) WithOptions(m Map) *HttpClient
- func (client *HttpClient) WithTrace(ctx interface{}, spanContextKey, name string, trace *zipkin.Tracer) *HttpClient
- type Map
- type Response
Constants ¶
const ( ErrDefault ErrTimeout ErrRedirectPolicy )
Package errors
const ( PROXY_HTTP int = iota PROXY_SOCKS4 PROXY_SOCKS5 PROXY_SOCKS4A // CURL like OPT OPT_AUTOREFERER OPT_FOLLOWLOCATION OPT_CONNECTTIMEOUT OPT_CONNECTTIMEOUT_MS OPT_MAXREDIRS OPT_PROXYTYPE OPT_TIMEOUT OPT_TIMEOUT_MS OPT_COOKIEJAR OPT_INTERFACE OPT_PROXY OPT_REFERER OPT_USERAGENT // Other OPT OPT_REDIRECT_POLICY OPT_PROXY_FUNC OPT_DEBUG OPT_UNSAFE_TLS OPT_CONTEXT OPT_BEFORE_REQUEST_FUNC OPT_AFTER_REQUEST_FUNC )
const (
USERAGENT = "gcal"
)
Constants definations CURL options, see https://github.com/bagder/curl/blob/169fedbdce93ecf14befb6e0e1ce6a2d480252a3/packages/OS400/curl.inc.in
Variables ¶
var Begin = defaultClient.Begin
var Defaults = defaultClient.Defaults
var CONST = map[string]int{ "OPT_AUTOREFERER": OPT_AUTOREFERER, "OPT_FOLLOWLOCATION": OPT_FOLLOWLOCATION, "OPT_CONNECTTIMEOUT": OPT_CONNECTTIMEOUT, "OPT_CONNECTTIMEOUT_MS": OPT_CONNECTTIMEOUT_MS, "OPT_MAXREDIRS": OPT_MAXREDIRS, "OPT_PROXYTYPE": OPT_PROXYTYPE, "OPT_TIMEOUT": OPT_TIMEOUT, "OPT_TIMEOUT_MS": OPT_TIMEOUT_MS, "OPT_COOKIEJAR": OPT_COOKIEJAR, "OPT_INTERFACE": OPT_INTERFACE, "OPT_PROXY": OPT_PROXY, "OPT_REFERER": OPT_REFERER, "OPT_USERAGENT": OPT_USERAGENT, "OPT_REDIRECT_POLICY": OPT_REDIRECT_POLICY, "OPT_PROXY_FUNC": OPT_PROXY_FUNC, "OPT_DEBUG": OPT_DEBUG, "OPT_UNSAFE_TLS": OPT_UNSAFE_TLS, "OPT_CONTEXT": OPT_CONTEXT, "OPT_BEFORE_REQUEST_FUNC": OPT_BEFORE_REQUEST_FUNC, "OPT_AFTER_REQUEST_FUNC": OPT_AFTER_REQUEST_FUNC, }
String map of options
var Delete = defaultClient.Delete
var Do = defaultClient.Do
var Get = defaultClient.Get
var Head = defaultClient.Head
var Post = defaultClient.Post
var PostJson = defaultClient.PostJson
var PostMultipart = defaultClient.PostMultipart
var Put = defaultClient.Put
var PutJson = defaultClient.PutJson
var WithCommonHeader = defaultClient.WithCommonHeader
var WithHeader = defaultClient.WithHeader
var WithHeaders = defaultClient.WithHeaders
var WithOption = defaultClient.WithOption
var WithOptions = defaultClient.WithOptions
var WithTrace = defaultClient.WithTrace
Functions ¶
Types ¶
type HttpClient ¶
type HttpClient struct { // trace_span Span zipkin.Span // span context key SpanContextKey string // Default headers of client client. Headers map[string]string // contains filtered or unexported fields }
Powerful and easy to use HTTP client.
func (*HttpClient) Begin ¶
func (client *HttpClient) Begin() *HttpClient
Begin marks the begining of a request, it's necessary for concurrent requests.
func (*HttpClient) Defaults ¶
func (client *HttpClient) Defaults(defaults Map) *HttpClient
Set default options and headers.
func (*HttpClient) Delete ¶
func (client *HttpClient) Delete(url string, params ...interface{}) (*Response, error)
The DELETE request
func (*HttpClient) Do ¶
func (client *HttpClient) Do(method string, url string, headers map[string]string, body io.Reader) (*Response, error)
Start a request, and get the response.
Usually we just need the Get and Post method.
func (*HttpClient) Get ¶
func (client *HttpClient) Get(url string, params ...interface{}) (*Response, error)
The GET request
func (*HttpClient) Head ¶
func (client *HttpClient) Head(url string) (*Response, error)
The HEAD request
func (*HttpClient) Post ¶
func (client *HttpClient) Post(url string, params interface{}) (*Response, error)
The POST request
With multipart set to true, the request will be encoded as "multipart/form-data".
If any of the params key starts with "@", it is considered as a form file (similar to CURL but different).
func (*HttpClient) PostJson ¶
func (client *HttpClient) PostJson(url string, data interface{}) (*Response, error)
func (*HttpClient) PostMultipart ¶
func (client *HttpClient) PostMultipart(url string, params interface{}) ( *Response, error)
Post with the request encoded as "multipart/form-data".
func (*HttpClient) PutJson ¶
func (client *HttpClient) PutJson(url string, data interface{}) (*Response, error)
Put json data
func (*HttpClient) WithCommonHeader ¶
func (client *HttpClient) WithCommonHeader(appName, appSecretKey string) *HttpClient
func (*HttpClient) WithHeader ¶
func (client *HttpClient) WithHeader(k string, v string) *HttpClient
Temporarily specify a header of the current request.
func (*HttpClient) WithHeaders ¶
func (client *HttpClient) WithHeaders(m map[string]string) *HttpClient
Temporarily specify multiple headers of the current request.
func (*HttpClient) WithOption ¶
func (client *HttpClient) WithOption(k int, v interface{}) *HttpClient
Temporarily specify an option of the current request.
func (*HttpClient) WithOptions ¶
func (client *HttpClient) WithOptions(m Map) *HttpClient
Temporarily specify multiple options of the current request.
func (*HttpClient) WithTrace ¶
func (client *HttpClient) WithTrace(ctx interface{}, spanContextKey, name string, trace *zipkin.Tracer) *HttpClient