Documentation ¶
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 (cc *HttpClient) Begin() *HttpClient
- func (cc *HttpClient) Connect(url string, params ...map[string]string) (*Response, error)
- func (cc *HttpClient) CookieValue(url_ string, key string) string
- func (cc *HttpClient) CookieValues(url string) map[string]string
- func (cc *HttpClient) Cookies(url_ string) []*http.Cookie
- func (cc *HttpClient) Defaults(defaults Map) *HttpClient
- func (cc *HttpClient) Delete(url string, params ...interface{}) (*Response, error)
- func (cc *HttpClient) Do(method string, url string, headers map[string]string, body io.Reader) (*Response, error)
- func (cc *HttpClient) Get(url string, params ...interface{}) (*Response, error)
- func (cc *HttpClient) Head(url string) (*Response, error)
- func (cc *HttpClient) Options(url string, params ...map[string]string) (*Response, error)
- func (cc *HttpClient) Patch(url string, params ...map[string]string) (*Response, error)
- func (cc *HttpClient) PatchJson(url string, data interface{}) (*Response, error)
- func (cc *HttpClient) Post(url string, params interface{}) (*Response, error)
- func (cc *HttpClient) PostJson(url string, data interface{}) (*Response, error)
- func (cc *HttpClient) PostMultipart(url string, params interface{}) (*Response, error)
- func (cc *HttpClient) Put(url string, body io.Reader) (*Response, error)
- func (cc *HttpClient) PutJson(url string, data interface{}) (*Response, error)
- func (cc *HttpClient) Trace(url string, params ...map[string]string) (*Response, error)
- func (cc *HttpClient) WithCookie(cookies ...*http.Cookie) *HttpClient
- func (cc *HttpClient) WithHeader(k string, v string) *HttpClient
- func (cc *HttpClient) WithHeaders(m map[string]string) *HttpClient
- func (cc *HttpClient) WithOption(k int, v interface{}) *HttpClient
- func (cc *HttpClient) WithOptions(m Map) *HttpClient
- type Map
- type ProxyURL
- type Response
Constants ¶
const ( ERR_DEFAULT ERR_TIMEOUT ERR_REDIRECT_POLICY )
Package errors
const ( VERSION = "0.6.6" USERAGENT = "go-httpclient v" + VERSION PROXY_HTTP = 0 PROXY_SOCKS4 = 4 PROXY_SOCKS5 = 5 PROXY_SOCKS4A = 6 // CURL like OPT OPT_AUTOREFERER = 58 OPT_FOLLOWLOCATION = 52 OPT_CONNECTTIMEOUT = 78 OPT_CONNECTTIMEOUT_MS = 156 OPT_MAXREDIRS = 68 OPT_PROXYTYPE = 101 OPT_TIMEOUT = 13 OPT_TIMEOUT_MS = 155 OPT_COOKIEJAR = 10082 OPT_INTERFACE = 10062 OPT_PROXY = 10004 OPT_REFERER = 10016 OPT_USERAGENT = 10018 // Other OPT OPT_REDIRECT_POLICY = 100000 OPT_PROXY_FUNC = 100001 OPT_DEBUG = 100002 OPT_UNSAFE_TLS = 100004 OPT_CONTEXT = 100005 )
Constants definations CURL options, see https://github.com/bagder/curl/blob/169fedbdce93ecf14befb6e0e1ce6a2d480252a3/packages/OS400/curl.inc.in
Variables ¶
var Begin = defaultClient.Begin
Begin -
var CONST = map[string]int{
"OPT_AUTOREFERER": 58,
"OPT_FOLLOWLOCATION": 52,
"OPT_CONNECTTIMEOUT": 78,
"OPT_CONNECTTIMEOUT_MS": 156,
"OPT_MAXREDIRS": 68,
"OPT_PROXYTYPE": 101,
"OPT_TIMEOUT": 13,
"OPT_TIMEOUT_MS": 155,
"OPT_COOKIEJAR": 10082,
"OPT_INTERFACE": 10062,
"OPT_PROXY": 10004,
"OPT_REFERER": 10016,
"OPT_USERAGENT": 10018,
"OPT_REDIRECT_POLICY": 100000,
"OPT_PROXY_FUNC": 100001,
"OPT_DEBUG": 100002,
"OPT_UNSAFE_TLS": 100004,
"OPT_CONTEXT": 100005,
}
CONST - String map of options
var Connect = defaultClient.Connect
Connect -
var CookieValue = defaultClient.CookieValue
CookieValue -
var CookieValues = defaultClient.CookieValues
CookieValues -
var Cookies = defaultClient.Cookies
Cookies -
var Defaults = defaultClient.Defaults
Defaults -
var Delete = defaultClient.Delete
Delete -
var Do = defaultClient.Do
Do -
var Get = defaultClient.Get
Get -
var Head = defaultClient.Head
Head -
var Options = defaultClient.Options
Options -
var Patch = defaultClient.Patch
Patch -
var PatchJson = defaultClient.PatchJson
PatchJson -
var Post = defaultClient.Post
Post -
var PostJson = defaultClient.PostJson
PostJson -
var PostMultipart = defaultClient.PostMultipart
PostMultipart -
var Put = defaultClient.Put
Put -
var PutJson = defaultClient.PutJson
PutJson -
var Trace = defaultClient.Trace
Trace -
var WithCookie = defaultClient.WithCookie
WithCookie -
var WithHeader = defaultClient.WithHeader
WithHeader -
var WithHeaders = defaultClient.WithHeaders
WithHeaders -
var WithOption = defaultClient.WithOption
WithOption -
var WithOptions = defaultClient.WithOptions
WithOptions -
Functions ¶
Types ¶
type Error ¶
Custom error
type HttpClient ¶
type HttpClient struct { // Default headers of cc client. Headers map[string]string // contains filtered or unexported fields }
HttpClient - Powerful and easy to use HTTP client.
func (*HttpClient) Begin ¶
func (cc *HttpClient) Begin() *HttpClient
Begin marks the begining of a request, it's necessary for concurrent requests.
func (*HttpClient) Connect ¶
The CONNECT request
func (*HttpClient) CookieValue ¶
func (cc *HttpClient) CookieValue(url_ string, key string) string
Get cookie value of a specified cookie name.
func (*HttpClient) CookieValues ¶
func (cc *HttpClient) CookieValues(url string) map[string]string
CookieValues - Get cookie values(k-v map) of the client jar.
func (*HttpClient) Cookies ¶
func (cc *HttpClient) Cookies(url_ string) []*http.Cookie
Get cookies of the client jar.
func (*HttpClient) Defaults ¶
func (cc *HttpClient) Defaults(defaults Map) *HttpClient
Defaults - Set default options and headers.
func (*HttpClient) Delete ¶
func (cc *HttpClient) Delete(url string, params ...interface{}) (*Response, error)
The DELETE request
func (*HttpClient) Do ¶
func (cc *HttpClient) Do(method string, url string, headers map[string]string, body io.Reader) (*Response, error)
Do -Start a request, and get the response. Usually we just need the Get and Post method.
func (*HttpClient) Get ¶
func (cc *HttpClient) Get(url string, params ...interface{}) (*Response, error)
The GET request
func (*HttpClient) Head ¶
func (cc *HttpClient) Head(url string) (*Response, error)
The HEAD request
func (*HttpClient) Options ¶
The OPTIONS request
func (*HttpClient) Patch ¶
The PATCH request
func (*HttpClient) PatchJson ¶
func (cc *HttpClient) PatchJson(url string, data interface{}) (*Response, error)
Patch json data
func (*HttpClient) Post ¶
func (cc *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 (cc *HttpClient) PostJson(url string, data interface{}) (*Response, error)
func (*HttpClient) PostMultipart ¶
func (cc *HttpClient) PostMultipart(url string, params interface{}) ( *Response, error)
Post with the request encoded as "multipart/form-data".
func (*HttpClient) Put ¶
The PUT request
func (*HttpClient) PutJson ¶
func (cc *HttpClient) PutJson(url string, data interface{}) (*Response, error)
Put json data
func (*HttpClient) Trace ¶
The TRACE request
func (*HttpClient) WithCookie ¶
func (cc *HttpClient) WithCookie(cookies ...*http.Cookie) *HttpClient
WithCookie - Specify cookies of the current request.
func (*HttpClient) WithHeader ¶
func (cc *HttpClient) WithHeader(k string, v string) *HttpClient
WithHeader - Temporarily specify a header of the current request.
func (*HttpClient) WithHeaders ¶
func (cc *HttpClient) WithHeaders(m map[string]string) *HttpClient
WithHeaders - Temporarily specify multiple headers of the current request.
func (*HttpClient) WithOption ¶
func (cc *HttpClient) WithOption(k int, v interface{}) *HttpClient
WithOption - Temporarily specify an option of the current request.
func (*HttpClient) WithOptions ¶
func (cc *HttpClient) WithOptions(m Map) *HttpClient
WithOptions - Temporarily specify multiple options of the current request.
type ProxyURL ¶
type ProxyURL struct { Host string Scheme string Path string Port int Origin string Username string Password string WithAuth bool }
ProxyURL -