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 SetJSONDecoder(enc jsoniter.API)
- func SetJSONEncoder(enc jsoniter.API)
- func SetProgressInterval(interval time.Duration)
- 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) SetProgressInterval(interval time.Duration)
- 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 SetJSONDecoder ¶ added in v0.3.1
SetJSONDecoder sets the custmized decorder for json
func SetJSONEncoder ¶ added in v0.3.1
SetJSONEncoder sets the custmized encorder for json
func SetProgressInterval ¶ added in v0.3.1
SetProgressInterval sets the progress reporting interval of both UploadProgress and DownloadProgress handler for the default client
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 Header ¶
Header represents http request header
func HeaderFromStruct ¶ added in v0.3.1
func HeaderFromStruct(v interface{}) Header
HeaderFromStruct init header from struct
func ParseStruct ¶ added in v0.3.1
ParseStruct parse struct into header
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) SetProgressInterval ¶ added in v0.3.1
SetProgressInterval sets the progress reporting interval of both UploadProgress and DownloadProgress handler
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)