Documentation ¶
Index ¶
- Constants
- type RedirectPolicy
- type Request
- func (req *Request) BasePath(p string) *Request
- func (req *Request) Body(v interface{}) *Request
- func (req *Request) ContentType(t string) *Request
- func (req *Request) Cookie(c *http.Cookie) *Request
- func (req *Request) Copy() *Request
- func (req *Request) Delete(url string, args ...interface{}) *Request
- func (req *Request) Do() *Response
- func (req *Request) File(path string, field ...string) *Request
- func (req *Request) FileFromReader(r io.Reader, name string, field string) *Request
- func (req *Request) Get(url string, args ...interface{}) *Request
- func (req *Request) Header(k, v string) *Request
- func (req *Request) Headers(v interface{}) *Request
- func (req *Request) Host(h string) *Request
- func (req *Request) JSON() *Request
- func (req *Request) MaxCode(code int) *Request
- func (req *Request) MaxRedirect(max int) *Request
- func (req *Request) Method(method string) *Request
- func (req *Request) Multipart() *Request
- func (req *Request) Patch(url string, args ...interface{}) *Request
- func (req *Request) Post(url string, args ...interface{}) *Request
- func (req *Request) Proxy(proxyURL string) *Request
- func (req *Request) Put(url string, args ...interface{}) *Request
- func (req *Request) Queries(v interface{}) *Request
- func (req *Request) Query(k, v string) *Request
- func (req *Request) RedirectPolicy(p RedirectPolicy) *Request
- func (req *Request) Retry(attempts int, interval time.Duration) *Request
- func (req *Request) Set(k string, v interface{}) *Request
- func (req *Request) Timeout(t time.Duration) *Request
- func (req *Request) Transport(r http.RoundTripper) *Request
- func (req *Request) URL(rawURL string) *Request
- func (req *Request) UnixSocket(path string) *Request
- func (req *Request) Validator(v ResponseValidator) *Request
- func (req *Request) WithContext(ctx context.Context) *Request
- type Response
- func (resp *Response) Body() io.Reader
- func (resp *Response) BodyBytes() ([]byte, error)
- func (resp *Response) BodyJSON(v interface{}) error
- func (resp *Response) BodyMarshal(v interface{}) error
- func (resp *Response) BodyString() (string, error)
- func (resp *Response) Error() error
- func (resp *Response) StatusCode() int
- type ResponseValidator
Constants ¶
const ( POST = "POST" GET = "GET" HEAD = "HEAD" PUT = "PUT" DELETE = "DELETE" PATCH = "PATCH" OPTIONS = "OPTIONS" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RedirectPolicy ¶
RedirectPolicy represents policy for handling redirections. It works like http.Client.CheckRedirect
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) ContentType ¶
func (*Request) File ¶
File adds a file from the given path to multipart field, with optional custom filedname. Calling this will automatically sets the body type to multipart. It will be considered an error if the body is of another type and not empty.
func (*Request) FileFromReader ¶
FileFromReader adds a file to the multipart from the given reader. Its behavior is the same as File. TODO: Maybe an io.ReadCloser?
func (*Request) MaxCode ¶
MaxCode tells the client the validate the request with the given max status code. If status code of a response is larger than it, the response is considered to be failed.
func (*Request) MaxRedirect ¶
MaxRedirect sets the maxium redirects of the request
func (*Request) Proxy ¶
Proxy sets the proxy used to perform the request. It supports http/https, and socks5 proxy.
func (*Request) RedirectPolicy ¶
func (req *Request) RedirectPolicy(p RedirectPolicy) *Request
RedirectPolicy adds a custom redirect policy to the request.
func (*Request) Transport ¶
func (req *Request) Transport(r http.RoundTripper) *Request
Transport sets a custom transport for the http client. If the transport is not a *http.Transport, no further customization can be done to the transport
func (*Request) UnixSocket ¶
UnixSocket sets the request to be sent to a unix socket.
func (*Request) Validator ¶
func (req *Request) Validator(v ResponseValidator) *Request
Validator sets a custom response validator
type Response ¶
type Response struct { // Raw is the underlying http.Response Raw *http.Response // FailedAttempts keeps all previous failed attempts through retries FailedAttempts []*Response // contains filtered or unexported fields }
func (*Response) BodyJSON ¶
BodyJSON marshalls the body content to the given interface as JSON, regardless of the Content-Type header in the response.
func (*Response) BodyMarshal ¶
BodyMarshal marshalls the body content to the given interface according to the content type.
func (*Response) BodyString ¶
BodyString returns the body as string
func (*Response) StatusCode ¶
type ResponseValidator ¶
ResponseValidator tells whether the given response is valid.