代码拉取完成,页面将自动刷新
/*
Package direwolf is a convenient and easy to use http client written in Golang.
*/
package direwolf
// Default global session
var defatultSession *Session
func init() {
sessionOptions := DefaultSessionOptions() // New default global session
sessionOptions.DisableCookieJar = true
defatultSession = NewSession(sessionOptions)
}
// Send is different with Get and Post method, you should pass a
// Request to it. You can construct Request by use NewRequest
// method.
func Send(req *Request) (*Response, error) {
resp, err := defatultSession.Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
// Get is the most common method of direwolf to constructs and sends a
// Get request.
//
// You can construct this request by passing the following parameters:
// url: URL for the request.
// http.Header: HTTP Headers to send.
// direwolf.Params: Parameters to send in the query string.
// direwolf.Cookies: Cookies to send.
// direwolf.PostForm: Post data form to send.
// direwolf.Body: Post body to send.
// direwolf.Proxy: Proxy url to use.
// direwolf.Timeout: Request Timeout. Default value is 30.
// direwolf.RedirectNum: Number of Request allowed to redirect. Default value is 5.
func Get(URL string, args ...RequestOption) (*Response, error) {
req, err := NewRequest("GET", URL, args...)
if err != nil {
return nil, err
}
resp, err := Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
// Post is the method to constructs and sends a Post request. Parameters are
// the same with direwolf.Get()
//
// Note: direwolf.Body can`t existed with direwolf.PostForm.
func Post(URL string, args ...RequestOption) (*Response, error) {
req, err := NewRequest("POST", URL, args...)
if err != nil {
return nil, err
}
resp, err := Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
// Head is the method to constructs and sends a Head request. Parameters are
// the same with direwolf.Get()
func Head(URL string, args ...RequestOption) (*Response, error) {
req, err := NewRequest("HEAD", URL, args...)
if err != nil {
return nil, err
}
resp, err := Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
// Put is the method to constructs and sends a Put request. Parameters are
// the same with direwolf.Get()
func Put(URL string, args ...RequestOption) (*Response, error) {
req, err := NewRequest("Put", URL, args...)
if err != nil {
return nil, err
}
resp, err := Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
// Patch is the method to constructs and sends a Patch request. Parameters are
// the same with direwolf.Get()
func Patch(URL string, args ...RequestOption) (*Response, error) {
req, err := NewRequest("Patch", URL, args...)
if err != nil {
return nil, err
}
resp, err := Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
// Delete is the method to constructs and sends a Delete request. Parameters are
// the same with direwolf.Get()
func Delete(URL string, args ...RequestOption) (*Response, error) {
req, err := NewRequest("Delete", URL, args...)
if err != nil {
return nil, err
}
resp, err := Send(req)
if err != nil {
return nil, err
}
return resp, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。