Documentation ¶
Overview ¶
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client
Index ¶
- Variables
- type Request
- type Response
- type SuperAgent
- func (s *SuperAgent) ClearSuperAgent()
- func (s *SuperAgent) End(callback ...func(response Response, body string)) (Response, string, error)
- func (s *SuperAgent) Get(targetUrl string) *SuperAgent
- func (s *SuperAgent) Post(targetUrl string) *SuperAgent
- func (s *SuperAgent) Query(content string) *SuperAgent
- func (s *SuperAgent) RedirectPolicy(policy func(req Request, via []Request) error) *SuperAgent
- func (s *SuperAgent) Send(content string) *SuperAgent
- func (s *SuperAgent) Set(param string, value string) *SuperAgent
- func (s *SuperAgent) Type(typeStr string) *SuperAgent
Constants ¶
This section is empty.
Variables ¶
View Source
var Types = map[string]string{
"html": "text/html",
"json": "application/json",
"xml": "application/xml",
"urlencoded": "application/x-www-form-urlencoded",
"form": "application/x-www-form-urlencoded",
"form-data": "application/x-www-form-urlencoded",
}
Functions ¶
This section is empty.
Types ¶
type SuperAgent ¶
type SuperAgent struct { Url string Method string Header map[string]string TargetType string ForceType string Data map[string]interface{} FormData url.Values QueryData url.Values Client *http.Client }
A SuperAgent is a object storing all request data for client.
func (*SuperAgent) ClearSuperAgent ¶
func (s *SuperAgent) ClearSuperAgent()
Clear SuperAgent data for another new request.
func (*SuperAgent) Get ¶
func (s *SuperAgent) Get(targetUrl string) *SuperAgent
func (*SuperAgent) Post ¶
func (s *SuperAgent) Post(targetUrl string) *SuperAgent
func (*SuperAgent) Query ¶
func (s *SuperAgent) Query(content string) *SuperAgent
Query method accepts ether json string or strings which will form a query-string in url of GET method or body of POST method. For example, making "/search?query=bicycle&size=50x50&weight=20kg" using GET method:
gorequest.New(). Get('/search'). Query(`{ query: 'bicycle' }`). Query(`{ size: '50x50' }`). Query(`{ weight: '20kg' }`). End()
Or you can put multiple json values:
gorequest.New(). Get('/search'). Query(`{ query: 'bicycle', size: '50x50', weight: '20kg' }`). End()
Strings are also acceptable:
gorequest.New(). Get('/search'). Query('query=bicycle&size=50x50'). Query('weight=20kg'). End()
Or even Mixed! :)
gorequest.New(). Get('/search'). Query('query=bicycle'). Query(`{ size: '50x50', weight:'20kg' }`). End()
TODO: check error
func (*SuperAgent) RedirectPolicy ¶
func (s *SuperAgent) RedirectPolicy(policy func(req Request, via []Request) error) *SuperAgent
func (*SuperAgent) Send ¶
func (s *SuperAgent) Send(content string) *SuperAgent
func (*SuperAgent) Set ¶
func (s *SuperAgent) Set(param string, value string) *SuperAgent
func (*SuperAgent) Type ¶
func (s *SuperAgent) Type(typeStr string) *SuperAgent
Click to show internal directories.
Click to hide internal directories.