Documentation ¶
Index ¶
- Variables
- func After(fn func(*Client))
- func Before(fn func(*Client) error)
- func InitDiscovery(discovery *service.Discovery)
- func NewTransport() *http.Transport
- type Client
- func Delete(url string) *Client
- func Deletes(serviceName string) *Client
- func Get(url string) *Client
- func Gets(serviceName string) *Client
- func Head(url string) *Client
- func Heads(serviceName string) *Client
- func Patch(url string) *Client
- func Patchs(serviceName string) *Client
- func Post(url string) *Client
- func Posts(serviceName string) *Client
- func Put(url string) *Client
- func Puts(serviceName string) *Client
- func Service(serviceName, method string) *Client
- func (c *Client) Accept(accept string) *Client
- func (c *Client) Body(data interface{}) *Client
- func (c *Client) BodyWithContentType(data []byte, contentType string) *Client
- func (c *Client) Bytes() ([]byte, error)
- func (c *Client) CheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) *Client
- func (c *Client) Clear() *Client
- func (c *Client) Client(client *http.Client) *Client
- func (c *Client) Cookie(cookie *http.Cookie) *Client
- func (c *Client) Do() (resp *http.Response, err error)
- func (c *Client) EnableCookie(enableCookie bool) *Client
- func (c *Client) Error() error
- func (c *Client) File(fileName, path string) *Client
- func (c *Client) Files(paths map[string]string) *Client
- func (c *Client) HasError() bool
- func (c *Client) Header(key, value string) *Client
- func (c *Client) JSONBody(obj interface{}) *Client
- func (c *Client) JSONBodyWithError(obj interface{}) (*Client, error)
- func (c *Client) Jar(jar http.CookieJar) *Client
- func (c *Client) Logging() *Client
- func (c *Client) MarkTag(tag string) *Client
- func (c *Client) OK() bool
- func (c *Client) Param(key string, value interface{}) *Client
- func (c *Client) Params(values url.Values) *Client
- func (c *Client) Request(request *http.Request) *Client
- func (c *Client) Result(v interface{}) error
- func (c *Client) Retries(retries int) *Client
- func (c *Client) SetBasicAuth(username, password string) *Client
- func (c *Client) Settings(settings Settings) *Client
- func (c *Client) String() (string, error)
- func (c *Client) Title(title string) *Client
- func (c *Client) ToFile(filename string) error
- func (c *Client) ToJSON(v interface{}) error
- func (c *Client) ToMap(v *map[string]interface{}) error
- func (c *Client) ToXML(v interface{}) error
- func (c *Client) ToYAML(v interface{}) error
- func (c *Client) Transport(transport http.RoundTripper) *Client
- func (c *Client) Unlogging() *Client
- func (c *Client) UserAgent(useragent string) *Client
- func (c *Client) XMLBody(obj interface{}) *Client
- func (c *Client) XMLBodyWithError(obj interface{}) (*Client, error)
- func (c *Client) YAMLBody(obj interface{}) *Client
- func (c *Client) YAMLBodyWithError(obj interface{}) (*Client, error)
- type Settings
Constants ¶
This section is empty.
Variables ¶
var ( //DefaultRetries default retries 3 DefaultRetries = 3 //DefaultCookieJar default cookie jar DefaultCookieJar http.CookieJar )
Functions ¶
func InitDiscovery ¶
InitDiscovery init service discovery
Types ¶
type Client ¶
type Client struct { Req *http.Request Conf Settings Tag string // contains filtered or unexported fields }
Client http client
func Get ¶
Get issues a GET to the specified URL. If the response is one of the following redirect codes, Get follows the redirect, up to a maximum of 10 redirects:
301 (Moved Permanently) 302 (Found) 303 (See Other) 307 (Temporary Redirect) 308 (Permanent Redirect)
An error is returned if there were too many redirects or if there was an HTTP protocol error. A non-2xx response doesn't cause an error. Any returned error will be of type *url.Error. The url.Error value's Timeout method will report true if request timed out or was canceled.
When err is nil, resp always contains a non-nil resp.Body. Caller should close resp.Body when done reading from it.
Get is a wrapper around DefaultClient.Get.
To make a request with custom headers, use NewRequest and DefaultClient.Do.
func Head ¶
Head issues a HEAD to the specified URL. If the response is one of the following redirect codes, Head follows the redirect, up to a maximum of 10 redirects:
301 (Moved Permanently) 302 (Found) 303 (See Other) 307 (Temporary Redirect) 308 (Permanent Redirect)
Head is a wrapper around DefaultClient.Head
func Post ¶
Post issues a POST to the specified URL.
Caller should close resp.Body when done reading from it.
If the provided body is an io.Closer, it is closed after the request.
Post is a wrapper around DefaultClient.Post.
To set custom headers, use NewRequest and DefaultClient.Do.
See the Client.Do method documentation for details on how redirects are handled.
func (*Client) BodyWithContentType ¶
BodyWithContentType adds request raw body encoding by XML.
func (*Client) CheckRedirect ¶
func (c *Client) CheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) *Client
CheckRedirect proxy method http.Get
func (*Client) EnableCookie ¶
EnableCookie set enable cookie jar
func (*Client) JSONBodyWithError ¶
JSONBodyWithError adds request raw body encoding by JSON.
func (*Client) Param ¶
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*Client) Params ¶
Params adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*Client) Result ¶
Result returns the map that marshals from the body bytes as json or xml or yaml in response . default json
func (*Client) SetBasicAuth ¶
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
With HTTP Basic Authentication the provided username and password are not encrypted.
Some protocols may impose additional requirements on pre-escaping the username and password. For instance, when used with OAuth2, both arguments must be URL encoded first with url.QueryEscape.
func (*Client) ToFile ¶
ToFile saves the body data in response to one file. it calls Response inner.
func (*Client) ToJSON ¶
ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*Client) ToMap ¶
ToMap returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*Client) ToXML ¶
ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.
func (*Client) ToYAML ¶
ToYAML returns the map that marshals from the body bytes as yaml in response . it calls Response inner.
func (*Client) Transport ¶
func (c *Client) Transport(transport http.RoundTripper) *Client
Transport specifies the mechanism by which individual HTTP requests are made. If nil, DefaultTransport is used.
func (*Client) XMLBodyWithError ¶
XMLBodyWithError adds request raw body encoding by XML.
func (*Client) YAMLBodyWithError ¶
YAMLBodyWithError adds request raw body encoding by YAML.