Documentation ¶
Overview ¶
Package httplib is used as http.Client Usage:
import "github.com/W3-Engineers-Ltd/Radiant/client/httplib"
b := httplib.Post("http://radiant.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://radiant.me/docs/module/httplib.md
Index ¶
- func SetDefaultSetting(setting RadiantHTTPSettings)
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- type RadiantHTTPRequest
- func (b *RadiantHTTPRequest) Body(data interface{}) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) Bytes() ([]byte, error)
- func (b *RadiantHTTPRequest) DoRequest() (resp *http.Response, err error)
- func (b *RadiantHTTPRequest) GetRequest() *http.Request
- func (b *RadiantHTTPRequest) Header(key, value string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) JSONBody(obj interface{}) (*RadiantHTTPRequest, error)
- func (b *RadiantHTTPRequest) Param(key, value string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) PostFile(formname, filename string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) Response() (*http.Response, error)
- func (b *RadiantHTTPRequest) Retries(times int) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) RetryDelay(delay time.Duration) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetBasicAuth(username, password string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetCookie(cookie *http.Cookie) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetEnableCookie(enable bool) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetHost(host string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetProtocolVersion(vers string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetTLSClientConfig(config *tls.Config) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetTransport(transport http.RoundTripper) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) SetUserAgent(useragent string) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) Setting(setting RadiantHTTPSettings) *RadiantHTTPRequest
- func (b *RadiantHTTPRequest) String() (string, error)
- func (b *RadiantHTTPRequest) ToFile(filename string) error
- func (b *RadiantHTTPRequest) ToJSON(v interface{}) error
- func (b *RadiantHTTPRequest) ToXML(v interface{}) error
- func (b *RadiantHTTPRequest) ToYAML(v interface{}) error
- func (b *RadiantHTTPRequest) XMLBody(obj interface{}) (*RadiantHTTPRequest, error)
- func (b *RadiantHTTPRequest) YAMLBody(obj interface{}) (*RadiantHTTPRequest, error)
- type RadiantHTTPSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultSetting ¶
func SetDefaultSetting(setting RadiantHTTPSettings)
SetDefaultSetting Overwrite default settings
Types ¶
type RadiantHTTPRequest ¶
type RadiantHTTPRequest struct {
// contains filtered or unexported fields
}
RadiantHTTPRequest provides more useful methods for requesting one url than http.Request.
func Delete ¶
func Delete(url string) *RadiantHTTPRequest
Delete returns *RadiantHttpRequest DELETE method.
func Get ¶
func Get(url string) *RadiantHTTPRequest
Get returns *RadiantHttpRequest with GET method.
func Head ¶
func Head(url string) *RadiantHTTPRequest
Head returns *RadiantHttpRequest with HEAD method.
func NewRadiantRequest ¶
func NewRadiantRequest(rawurl, method string) *RadiantHTTPRequest
NewRadiantRequest return *RadiantHttpRequest with specific method
func Post ¶
func Post(url string) *RadiantHTTPRequest
Post returns *RadiantHttpRequest with POST method.
func Put ¶
func Put(url string) *RadiantHTTPRequest
Put returns *RadiantHttpRequest with PUT method.
func (*RadiantHTTPRequest) Body ¶
func (b *RadiantHTTPRequest) Body(data interface{}) *RadiantHTTPRequest
Body adds request raw body. it supports string and []byte.
func (*RadiantHTTPRequest) Bytes ¶
func (b *RadiantHTTPRequest) Bytes() ([]byte, error)
Bytes returns the body []byte in response. it calls Response inner.
func (*RadiantHTTPRequest) DoRequest ¶
func (b *RadiantHTTPRequest) DoRequest() (resp *http.Response, err error)
DoRequest will do the client.Do
func (*RadiantHTTPRequest) GetRequest ¶
func (b *RadiantHTTPRequest) GetRequest() *http.Request
GetRequest return the request object
func (*RadiantHTTPRequest) Header ¶
func (b *RadiantHTTPRequest) Header(key, value string) *RadiantHTTPRequest
Header add header item string in request.
func (*RadiantHTTPRequest) JSONBody ¶
func (b *RadiantHTTPRequest) JSONBody(obj interface{}) (*RadiantHTTPRequest, error)
JSONBody adds request raw body encoding by JSON.
func (*RadiantHTTPRequest) Param ¶
func (b *RadiantHTTPRequest) Param(key, value string) *RadiantHTTPRequest
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*RadiantHTTPRequest) PostFile ¶
func (b *RadiantHTTPRequest) PostFile(formname, filename string) *RadiantHTTPRequest
PostFile add a post file to the request
func (*RadiantHTTPRequest) Response ¶
func (b *RadiantHTTPRequest) Response() (*http.Response, error)
Response executes request client gets response mannually.
func (*RadiantHTTPRequest) Retries ¶
func (b *RadiantHTTPRequest) Retries(times int) *RadiantHTTPRequest
Retries sets Retries times. default is 0 means no retried. -1 means retried forever. others means retried times.
func (*RadiantHTTPRequest) RetryDelay ¶
func (b *RadiantHTTPRequest) RetryDelay(delay time.Duration) *RadiantHTTPRequest
func (*RadiantHTTPRequest) SetBasicAuth ¶
func (b *RadiantHTTPRequest) SetBasicAuth(username, password string) *RadiantHTTPRequest
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*RadiantHTTPRequest) SetCheckRedirect ¶
func (b *RadiantHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *RadiantHTTPRequest
SetCheckRedirect specifies the policy for handling redirects.
If CheckRedirect is nil, the Client uses its default policy, which is to stop after 10 consecutive requests.
func (*RadiantHTTPRequest) SetCookie ¶
func (b *RadiantHTTPRequest) SetCookie(cookie *http.Cookie) *RadiantHTTPRequest
SetCookie add cookie into request.
func (*RadiantHTTPRequest) SetEnableCookie ¶
func (b *RadiantHTTPRequest) SetEnableCookie(enable bool) *RadiantHTTPRequest
SetEnableCookie sets enable/disable cookiejar
func (*RadiantHTTPRequest) SetHost ¶
func (b *RadiantHTTPRequest) SetHost(host string) *RadiantHTTPRequest
SetHost set the request host
func (*RadiantHTTPRequest) SetProtocolVersion ¶
func (b *RadiantHTTPRequest) SetProtocolVersion(vers string) *RadiantHTTPRequest
SetProtocolVersion Set the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*RadiantHTTPRequest) SetProxy ¶
func (b *RadiantHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *RadiantHTTPRequest
SetProxy set the http proxy example:
func(req *http.Request) (*url.URL, error) { u, _ := url.ParseRequestURI("http://127.0.0.1:8118") return u, nil }
func (*RadiantHTTPRequest) SetTLSClientConfig ¶
func (b *RadiantHTTPRequest) SetTLSClientConfig(config *tls.Config) *RadiantHTTPRequest
SetTLSClientConfig sets tls connection configurations if visiting https url.
func (*RadiantHTTPRequest) SetTimeout ¶
func (b *RadiantHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *RadiantHTTPRequest
SetTimeout sets connect time out and read-write time out for RadiantRequest.
func (*RadiantHTTPRequest) SetTransport ¶
func (b *RadiantHTTPRequest) SetTransport(transport http.RoundTripper) *RadiantHTTPRequest
SetTransport set the setting transport
func (*RadiantHTTPRequest) SetUserAgent ¶
func (b *RadiantHTTPRequest) SetUserAgent(useragent string) *RadiantHTTPRequest
SetUserAgent sets User-Agent header field
func (*RadiantHTTPRequest) Setting ¶
func (b *RadiantHTTPRequest) Setting(setting RadiantHTTPSettings) *RadiantHTTPRequest
Setting Change request settings
func (*RadiantHTTPRequest) String ¶
func (b *RadiantHTTPRequest) String() (string, error)
String returns the body string in response. it calls Response inner.
func (*RadiantHTTPRequest) ToFile ¶
func (b *RadiantHTTPRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*RadiantHTTPRequest) ToJSON ¶
func (b *RadiantHTTPRequest) ToJSON(v interface{}) error
ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*RadiantHTTPRequest) ToXML ¶
func (b *RadiantHTTPRequest) ToXML(v interface{}) error
ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.
func (*RadiantHTTPRequest) ToYAML ¶
func (b *RadiantHTTPRequest) ToYAML(v interface{}) error
ToYAML returns the map that marshals from the body bytes as yaml in response . it calls Response inner.
func (*RadiantHTTPRequest) XMLBody ¶
func (b *RadiantHTTPRequest) XMLBody(obj interface{}) (*RadiantHTTPRequest, error)
XMLBody adds request raw body encoding by XML.
func (*RadiantHTTPRequest) YAMLBody ¶
func (b *RadiantHTTPRequest) YAMLBody(obj interface{}) (*RadiantHTTPRequest, error)
YAMLBody adds request raw body encoding by YAML.
type RadiantHTTPSettings ¶
type RadiantHTTPSettings httplib.RadiantHTTPSettings
RadiantHTTPSettings is the http.Client setting