Documentation ¶
Overview ¶
Powerful and easy to use http client
Powerful and easy to use http client
Index ¶
- Constants
- Variables
- func IsRedirectError(err error) bool
- func IsTimeoutError(err error) bool
- func Option(o map[string]interface{}) map[int]interface{}
- type Error
- type HttpClient
- func (this *HttpClient) Begin() *HttpClient
- func (this *HttpClient) Connect(url string, params ...map[string]string) (*Response, error)
- func (this *HttpClient) CookieValue(url_ string, key string) string
- func (this *HttpClient) CookieValues(url_ string) map[string]string
- func (this *HttpClient) Cookies(url_ string) []*http.Cookie
- func (this *HttpClient) Defaults(defaults Map) *HttpClient
- func (this *HttpClient) Delete(url string, params ...interface{}) (*Response, error)
- func (this *HttpClient) DeleteJson(url string, data interface{}) (*Response, error)
- func (this *HttpClient) Do(method string, url string, headers map[string]string, body io.Reader) (*Response, error)
- func (this *HttpClient) Get(url string, params ...interface{}) (*Response, error)
- func (this *HttpClient) Head(url string) (*Response, error)
- func (this *HttpClient) Options(url string, params ...map[string]string) (*Response, error)
- func (this *HttpClient) Patch(url string, params ...map[string]string) (*Response, error)
- func (this *HttpClient) PatchJson(url string, data interface{}) (*Response, error)
- func (this *HttpClient) Post(url string, params interface{}) (*Response, error)
- func (this *HttpClient) PostJson(url string, data interface{}) (*Response, error)
- func (this *HttpClient) PostMultipart(url string, params interface{}) (*Response, error)
- func (this *HttpClient) Put(url string, body io.Reader) (*Response, error)
- func (this *HttpClient) PutJson(url string, data interface{}) (*Response, error)
- func (this *HttpClient) Trace(url string, params ...map[string]string) (*Response, error)
- func (this *HttpClient) WithCookie(cookies ...*http.Cookie) *HttpClient
- func (this *HttpClient) WithHeader(k string, v string) *HttpClient
- func (this *HttpClient) WithHeaders(m map[string]string) *HttpClient
- func (this *HttpClient) WithOption(k int, v interface{}) *HttpClient
- func (this *HttpClient) WithOptions(m Map) *HttpClient
- type Map
- type Response
Constants ¶
const ( ERR_DEFAULT ERR_TIMEOUT ERR_REDIRECT_POLICY )
Package errors
const ( VERSION = "0.6.9" USERAGENT = "go-httpclient v" + VERSION )
Constants definations CURL options, see https://github.com/bagder/curl/blob/169fedbdce93ecf14befb6e0e1ce6a2d480252a3/packages/OS400/curl.inc.in
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_BEFORE_RESPONSE_FUNC )
Variables ¶
var Begin = defaultClient.Begin
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_BEFORE_RESPONSE_FUNC": OPT_BEFORE_RESPONSE_FUNC, }
String map of options
var Connect = defaultClient.Connect
var CookieValue = defaultClient.CookieValue
var CookieValues = defaultClient.CookieValues
var Cookies = defaultClient.Cookies
var Defaults = defaultClient.Defaults
var Delete = defaultClient.Delete
var Do = defaultClient.Do
var Get = defaultClient.Get
var Head = defaultClient.Head
var Options = defaultClient.Options
var Patch = defaultClient.Patch
var PatchJson = defaultClient.PatchJson
var Post = defaultClient.Post
var PostJson = defaultClient.PostJson
var PostMultipart = defaultClient.PostMultipart
var Put = defaultClient.Put
var PutJson = defaultClient.PutJson
var Trace = defaultClient.Trace
var WithCookie = defaultClient.WithCookie
var WithHeader = defaultClient.WithHeader
var WithHeaders = defaultClient.WithHeaders
var WithOption = defaultClient.WithOption
var WithOptions = defaultClient.WithOptions
Functions ¶
Types ¶
type HttpClient ¶
type HttpClient struct { // Default headers of this client. Headers map[string]string // contains filtered or unexported fields }
Powerful and easy to use HTTP client.
func (*HttpClient) Begin ¶ added in v0.3.0
func (this *HttpClient) Begin() *HttpClient
Begin marks the begining of a request, it's necessary for concurrent requests.
func (*HttpClient) CookieValue ¶ added in v0.3.2
func (this *HttpClient) CookieValue(url_ string, key string) string
Get cookie value of a specified cookie name.
func (*HttpClient) CookieValues ¶ added in v0.3.2
func (this *HttpClient) CookieValues(url_ string) map[string]string
Get cookie values(k-v map) of the client jar.
func (*HttpClient) Cookies ¶ added in v0.3.2
func (this *HttpClient) Cookies(url_ string) []*http.Cookie
Get cookies of the client jar.
func (*HttpClient) Defaults ¶ added in v0.5.0
func (this *HttpClient) Defaults(defaults Map) *HttpClient
Set default options and headers.
func (*HttpClient) Delete ¶ added in v0.5.1
func (this *HttpClient) Delete(url string, params ...interface{}) (*Response, error)
The DELETE request
func (*HttpClient) DeleteJson ¶ added in v0.7.0
func (this *HttpClient) DeleteJson(url string, data interface{}) (*Response, error)
delete json data
func (*HttpClient) Do ¶ added in v0.2.1
func (this *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 (this *HttpClient) Get(url string, params ...interface{}) (*Response, error)
The GET request
func (*HttpClient) Head ¶ added in v0.5.1
func (this *HttpClient) Head(url string) (*Response, error)
The HEAD request
func (*HttpClient) PatchJson ¶ added in v0.6.3
func (this *HttpClient) PatchJson(url string, data interface{}) (*Response, error)
Patch json data
func (*HttpClient) Post ¶
func (this *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 ¶ added in v0.5.1
func (this *HttpClient) PostJson(url string, data interface{}) (*Response, error)
func (*HttpClient) PostMultipart ¶ added in v0.2.1
func (this *HttpClient) PostMultipart(url string, params interface{}) ( *Response, error)
Post with the request encoded as "multipart/form-data".
func (*HttpClient) PutJson ¶ added in v0.5.1
func (this *HttpClient) PutJson(url string, data interface{}) (*Response, error)
Put json data
func (*HttpClient) WithCookie ¶ added in v0.3.0
func (this *HttpClient) WithCookie(cookies ...*http.Cookie) *HttpClient
Specify cookies of the current request.
func (*HttpClient) WithHeader ¶ added in v0.2.1
func (this *HttpClient) WithHeader(k string, v string) *HttpClient
Temporarily specify a header of the current request.
func (*HttpClient) WithHeaders ¶ added in v0.2.1
func (this *HttpClient) WithHeaders(m map[string]string) *HttpClient
Temporarily specify multiple headers of the current request.
func (*HttpClient) WithOption ¶ added in v0.2.1
func (this *HttpClient) WithOption(k int, v interface{}) *HttpClient
Temporarily specify an option of the current request.
func (*HttpClient) WithOptions ¶ added in v0.2.1
func (this *HttpClient) WithOptions(m Map) *HttpClient
Temporarily specify multiple options of the current request.
type Map ¶ added in v0.4.0
type Map map[interface{}]interface{}
Map is a mixed structure with options and headers