Categorygithub.com/Pow-Duck/httplib
modulepackage
0.0.1
Repository: https://github.com/pow-duck/httplib.git
Documentation: pkg.go.dev

# README

httplib

httplib is an libs help you to curl remote url.

How to use?

GET

you can use Get to crawl data.

import "github.com/Pow-Duck/httplib"

str, err := httplib.Get("http://beego.me/").String()
if err != nil {
    	// error
}
fmt.Println(str)

POST

POST data to remote url

req := httplib.Post("http://beego.me/")
req.Param("username","astaxie")
req.Param("password","123456")
str, err := req.String()
if err != nil {
    	// error
}
fmt.Println(str)

Set timeout

The default timeout is 60 seconds, function prototype:

SetTimeout(connectTimeout, readWriteTimeout time.Duration)

Example:

// GET
httplib.Get("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second)

// POST
httplib.Post("http://beego.me/").SetTimeout(100 * time.Second, 30 * time.Second)

Debug

If you want to debug the request info, set the debug on

httplib.Get("http://beego.me/").Debug(true)

Set HTTP Basic Auth

str, err := Get("http://beego.me/").SetBasicAuth("user", "passwd").String()
if err != nil {
    	// error
}
fmt.Println(str)

Set HTTPS

If request url is https, You can set the client support TSL:

httplib.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})

More info about the tls.Config please visit http://golang.org/pkg/crypto/tls/#Config

Set HTTP Version

some servers need to specify the protocol version of HTTP

httplib.Get("http://beego.me/").SetProtocolVersion("HTTP/1.1")

Set Cookie

some http request need setcookie. So set it like this:

cookie := &http.Cookie{}
cookie.Name = "username"
cookie.Value  = "astaxie"
httplib.Get("http://beego.me/").SetCookie(cookie)

Upload file

httplib support mutil file upload, use req.PostFile()

req := httplib.Post("http://beego.me/")
req.Param("username","astaxie")
req.PostFile("uploadfile1", "httplib.pdf")
str, err := req.String()
if err != nil {
    	// error
}
fmt.Println(str)

See godoc for further documentation and examples.

# Packages

No description provided by the author
No description provided by the author
Package logs provide a general log interface Usage: import "github.com/Pow-Duck/httplib/logs" log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel Use it like this: log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md.
No description provided by the author
No description provided by the author

# Functions

AddDefaultFilter add a new filter into defaultSetting Be careful about using this method if you invoke SetDefaultSetting somewhere.
Delete returns *BeegoHttpRequest DELETE method.
Get returns *BeegoHttpRequest with GET method.
Head returns *BeegoHttpRequest with HEAD method.
NewBeegoRequest returns *BeegoHttpRequest with specific method TODO add error as return value I think if we don't return error users are hard to check whether we create Beego request successfully.
NewHttpResponseWithJsonBody will try to convert the data to json format usually you only use this when you want to mock http Response.
Post
Post returns *BeegoHttpRequest with POST method.
Put returns *BeegoHttpRequest with PUT method.
SetDefaultSetting overwrites default settings Keep in mind that when you invoke the SetDefaultSetting some methods invoked before SetDefaultSetting.
TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

BeegoHTTPRequest provides more useful methods than http.Request for requesting a url.
BeegoHTTPSettings is the http.Client setting.

# Type aliases

No description provided by the author
No description provided by the author