Documentation ¶
Index ¶
- Constants
- Variables
- func BodyJSON(v interface{}) *bodyJson
- func BodyXML(v interface{}) *bodyXml
- func Client() *http.Client
- func EnableCookie(enable bool)
- func EnableInsecureTLS(enable bool)
- func File(patterns ...string) interface{}
- func Flags() int
- func SetClient(client *http.Client)
- func SetFlags(flags int)
- func SetJSONEscapeHTML(escape bool)
- func SetJSONIndent(prefix, indent string)
- func SetProxy(proxy func(*http.Request) (*url.URL, error)) error
- func SetProxyUrl(rawurl string) error
- func SetTimeout(d time.Duration)
- func SetXMLIndent(prefix, indent string)
- type DownloadProgress
- type FileUpload
- type Header
- type Host
- type Param
- type QueryParam
- type Req
- func (r *Req) Client() *http.Client
- func (r *Req) Delete(url string, v ...interface{}) (*Resp, error)
- func (r *Req) Do(method, rawurl string, vs ...interface{}) (resp *Resp, err error)
- func (r *Req) EnableCookie(enable bool)
- func (r *Req) EnableInsecureTLS(enable bool)
- func (r *Req) Flags() int
- func (r *Req) Get(url string, v ...interface{}) (*Resp, error)
- func (r *Req) Head(url string, v ...interface{}) (*Resp, error)
- func (r *Req) Options(url string, v ...interface{}) (*Resp, error)
- func (r *Req) Patch(url string, v ...interface{}) (*Resp, error)
- func (r *Req) Post(url string, v ...interface{}) (*Resp, error)
- func (r *Req) Put(url string, v ...interface{}) (*Resp, error)
- func (r *Req) SetClient(client *http.Client)
- func (r *Req) SetFlags(flags int)
- func (r *Req) SetJSONEscapeHTML(escape bool)
- func (r *Req) SetJSONIndent(prefix, indent string)
- func (r *Req) SetProxy(proxy func(*http.Request) (*url.URL, error)) error
- func (r *Req) SetProxyUrl(rawurl string) error
- func (r *Req) SetTimeout(d time.Duration)
- func (r *Req) SetXMLIndent(prefix, indent string)
- type Resp
- func Delete(url string, v ...interface{}) (*Resp, error)
- func Do(method, url string, v ...interface{}) (*Resp, error)
- func Get(url string, v ...interface{}) (*Resp, error)
- func Head(url string, v ...interface{}) (*Resp, error)
- func Options(url string, v ...interface{}) (*Resp, error)
- func Patch(url string, v ...interface{}) (*Resp, error)
- func Post(url string, v ...interface{}) (*Resp, error)
- func Put(url string, v ...interface{}) (*Resp, error)
- func (r *Resp) Bytes() []byte
- func (r *Resp) Cost() time.Duration
- func (r *Resp) Dump() string
- func (r *Resp) Format(s fmt.State, verb rune)
- func (r *Resp) Request() *http.Request
- func (r *Resp) Response() *http.Response
- func (r *Resp) String() string
- func (r *Resp) ToBytes() ([]byte, error)
- func (r *Resp) ToFile(name string) error
- func (r *Resp) ToJSON(v interface{}) error
- func (r *Resp) ToString() (string, error)
- func (r *Resp) ToXML(v interface{}) error
- func (m Resp) Upload(req *http.Request)
- type UploadProgress
Constants ¶
const ( LreqHead = 1 << iota // output request head (request line and request header) LreqBody // output request body LrespHead // output response head (response line and response header) LrespBody // output response body Lcost // output time costed by the request LstdFlags = LreqHead | LreqBody | LrespHead | LrespBody )
flags to decide which part can be outputed
Variables ¶
var Debug bool
Debug enable debug mode if set to true
Functions ¶
func BodyJSON ¶
func BodyJSON(v interface{}) *bodyJson
BodyJSON make the object be encoded in json format and set it to the request body
func BodyXML ¶
func BodyXML(v interface{}) *bodyXml
BodyXML make the object be encoded in xml format and set it to the request body
func EnableInsecureTLS ¶
func EnableInsecureTLS(enable bool)
func File ¶
func File(patterns ...string) interface{}
File upload files matching the name pattern such as /usr/*/bin/go* (assuming the Separator is '/')
func SetJSONEscapeHTML ¶
func SetJSONEscapeHTML(escape bool)
SetJSONEscapeHTML specifies whether problematic HTML characters should be escaped inside JSON quoted strings. The default behavior is to escape &, <, and > to \u0026, \u003c, and \u003e to avoid certain safety problems that can arise when embedding JSON in HTML.
In non-HTML settings where the escaping interferes with the readability of the output, SetEscapeHTML(false) disables this behavior.
func SetJSONIndent ¶
func SetJSONIndent(prefix, indent string)
SetJSONIndent instructs the encoder to format each subsequent encoded value as if indented by the package-level function Indent(dst, src, prefix, indent). Calling SetIndent("", "") disables indentation.
func SetProxyUrl ¶
SetProxyUrl set the simple proxy with fixed proxy url
func SetXMLIndent ¶
func SetXMLIndent(prefix, indent string)
SetXMLIndent sets the encoder to generate XML in which each element begins on a new indented line that starts with prefix and is followed by one or more copies of indent according to the nesting depth.
Types ¶
type DownloadProgress ¶ added in v0.1.6
type DownloadProgress func(current, total int64)
type FileUpload ¶
type FileUpload struct { // filename in multipart form. FileName string // form field name FieldName string // file to uplaod, required File io.ReadCloser }
FileUpload represents a file to upload
type QueryParam ¶
type QueryParam map[string]interface{}
QueryParam is used to force append http request param to the uri
type Req ¶
type Req struct {
// contains filtered or unexported fields
}
Req is a convenient client for initiating requests
func (*Req) Do ¶
Do execute a http request with sepecify method and url, and it can also have some optional params, depending on your needs.
func (*Req) EnableCookie ¶
EnableCookieenable or disable cookie manager
func (*Req) EnableInsecureTLS ¶
EnableInsecureTLS allows insecure https
func (*Req) SetJSONEscapeHTML ¶
SetJSONEscapeHTML specifies whether problematic HTML characters should be escaped inside JSON quoted strings. The default behavior is to escape &, <, and > to \u0026, \u003c, and \u003e to avoid certain safety problems that can arise when embedding JSON in HTML.
In non-HTML settings where the escaping interferes with the readability of the output, SetEscapeHTML(false) disables this behavior.
func (*Req) SetJSONIndent ¶
SetJSONIndent instructs the encoder to format each subsequent encoded value as if indented by the package-level function Indent(dst, src, prefix, indent). Calling SetIndent("", "") disables indentation.
func (*Req) SetProxyUrl ¶
SetProxyUrl set the simple proxy with fixed proxy url
func (*Req) SetTimeout ¶
SetTimeout sets the timeout for every request
func (*Req) SetXMLIndent ¶
SetXMLIndent sets the encoder to generate XML in which each element begins on a new indented line that starts with prefix and is followed by one or more copies of indent according to the nesting depth.
type Resp ¶
type Resp struct {
// contains filtered or unexported fields
}
Resp represents a request with it's response
func (*Resp) ToBytes ¶ added in v0.1.4
ToBytes returns response body as []byte, return error if error happend when reading the response body
func (*Resp) ToString ¶ added in v0.1.4
ToString returns response body as string, return error if error happend when reading the response body
type UploadProgress ¶ added in v0.1.6
type UploadProgress func(current, total int64)