Documentation ¶
Overview ¶
Package httplib is used as http.Client Usage:
import "github.com/izi-global/izigo/httplib"
b := httplib.Post("http://go.izi.asia/") b.Param("username","diepdt") 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://go.izi.asia/docs/module/httplib.md
Index ¶
- func SetDefaultSetting(setting IZIGoHTTPSettings)
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- type IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) Body(data interface{}) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) Bytes() ([]byte, error)
- func (b *IZIGoHTTPRequest) Debug(isdebug bool) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) DoRequest() (resp *http.Response, err error)
- func (b *IZIGoHTTPRequest) DumpBody(isdump bool) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) DumpRequest() []byte
- func (b *IZIGoHTTPRequest) GetRequest() *http.Request
- func (b *IZIGoHTTPRequest) Header(key, value string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) JSONBody(obj interface{}) (*IZIGoHTTPRequest, error)
- func (b *IZIGoHTTPRequest) Param(key, value string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) PostFile(formname, filename string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) Response() (*http.Response, error)
- func (b *IZIGoHTTPRequest) Retries(times int) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetBasicAuth(username, password string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetCookie(cookie *http.Cookie) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetEnableCookie(enable bool) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetHost(host string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetProtocolVersion(vers string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetTLSClientConfig(config *tls.Config) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetTransport(transport http.RoundTripper) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) SetUserAgent(useragent string) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) Setting(setting IZIGoHTTPSettings) *IZIGoHTTPRequest
- func (b *IZIGoHTTPRequest) String() (string, error)
- func (b *IZIGoHTTPRequest) ToFile(filename string) error
- func (b *IZIGoHTTPRequest) ToJSON(v interface{}) error
- func (b *IZIGoHTTPRequest) ToXML(v interface{}) error
- func (b *IZIGoHTTPRequest) ToYAML(v interface{}) error
- func (b *IZIGoHTTPRequest) XMLBody(obj interface{}) (*IZIGoHTTPRequest, error)
- func (b *IZIGoHTTPRequest) YAMLBody(obj interface{}) (*IZIGoHTTPRequest, error)
- type IZIGoHTTPSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultSetting ¶
func SetDefaultSetting(setting IZIGoHTTPSettings)
SetDefaultSetting Overwrite default settings
Types ¶
type IZIGoHTTPRequest ¶
type IZIGoHTTPRequest struct {
// contains filtered or unexported fields
}
IZIGoHTTPRequest provides more useful methods for requesting one url than http.Request.
func Delete ¶
func Delete(url string) *IZIGoHTTPRequest
Delete returns *IZIGoHttpRequest DELETE method.
func Head ¶
func Head(url string) *IZIGoHTTPRequest
Head returns *IZIGoHttpRequest with HEAD method.
func NewIZIGoRequest ¶
func NewIZIGoRequest(rawurl, method string) *IZIGoHTTPRequest
NewIZIGoRequest return *IZIGoHttpRequest with specific method
func Post ¶
func Post(url string) *IZIGoHTTPRequest
Post returns *IZIGoHttpRequest with POST method.
func (*IZIGoHTTPRequest) Body ¶
func (b *IZIGoHTTPRequest) Body(data interface{}) *IZIGoHTTPRequest
Body adds request raw body. it supports string and []byte.
func (*IZIGoHTTPRequest) Bytes ¶
func (b *IZIGoHTTPRequest) Bytes() ([]byte, error)
Bytes returns the body []byte in response. it calls Response inner.
func (*IZIGoHTTPRequest) Debug ¶
func (b *IZIGoHTTPRequest) Debug(isdebug bool) *IZIGoHTTPRequest
Debug sets show debug or not when executing request.
func (*IZIGoHTTPRequest) DoRequest ¶
func (b *IZIGoHTTPRequest) DoRequest() (resp *http.Response, err error)
DoRequest will do the client.Do
func (*IZIGoHTTPRequest) DumpBody ¶
func (b *IZIGoHTTPRequest) DumpBody(isdump bool) *IZIGoHTTPRequest
DumpBody setting whether need to Dump the Body.
func (*IZIGoHTTPRequest) DumpRequest ¶
func (b *IZIGoHTTPRequest) DumpRequest() []byte
DumpRequest return the DumpRequest
func (*IZIGoHTTPRequest) GetRequest ¶
func (b *IZIGoHTTPRequest) GetRequest() *http.Request
GetRequest return the request object
func (*IZIGoHTTPRequest) Header ¶
func (b *IZIGoHTTPRequest) Header(key, value string) *IZIGoHTTPRequest
Header add header item string in request.
func (*IZIGoHTTPRequest) JSONBody ¶
func (b *IZIGoHTTPRequest) JSONBody(obj interface{}) (*IZIGoHTTPRequest, error)
JSONBody adds request raw body encoding by JSON.
func (*IZIGoHTTPRequest) Param ¶
func (b *IZIGoHTTPRequest) Param(key, value string) *IZIGoHTTPRequest
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*IZIGoHTTPRequest) PostFile ¶
func (b *IZIGoHTTPRequest) PostFile(formname, filename string) *IZIGoHTTPRequest
PostFile add a post file to the request
func (*IZIGoHTTPRequest) Response ¶
func (b *IZIGoHTTPRequest) Response() (*http.Response, error)
Response executes request client gets response mannually.
func (*IZIGoHTTPRequest) Retries ¶
func (b *IZIGoHTTPRequest) Retries(times int) *IZIGoHTTPRequest
Retries sets Retries times. default is 0 means no retried. -1 means retried forever. others means retried times.
func (*IZIGoHTTPRequest) SetBasicAuth ¶
func (b *IZIGoHTTPRequest) SetBasicAuth(username, password string) *IZIGoHTTPRequest
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*IZIGoHTTPRequest) SetCheckRedirect ¶
func (b *IZIGoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *IZIGoHTTPRequest
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 (*IZIGoHTTPRequest) SetCookie ¶
func (b *IZIGoHTTPRequest) SetCookie(cookie *http.Cookie) *IZIGoHTTPRequest
SetCookie add cookie into request.
func (*IZIGoHTTPRequest) SetEnableCookie ¶
func (b *IZIGoHTTPRequest) SetEnableCookie(enable bool) *IZIGoHTTPRequest
SetEnableCookie sets enable/disable cookiejar
func (*IZIGoHTTPRequest) SetHost ¶
func (b *IZIGoHTTPRequest) SetHost(host string) *IZIGoHTTPRequest
SetHost set the request host
func (*IZIGoHTTPRequest) SetProtocolVersion ¶
func (b *IZIGoHTTPRequest) SetProtocolVersion(vers string) *IZIGoHTTPRequest
SetProtocolVersion Set the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*IZIGoHTTPRequest) SetProxy ¶
func (b *IZIGoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *IZIGoHTTPRequest
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 (*IZIGoHTTPRequest) SetTLSClientConfig ¶
func (b *IZIGoHTTPRequest) SetTLSClientConfig(config *tls.Config) *IZIGoHTTPRequest
SetTLSClientConfig sets tls connection configurations if visiting https url.
func (*IZIGoHTTPRequest) SetTimeout ¶
func (b *IZIGoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *IZIGoHTTPRequest
SetTimeout sets connect time out and read-write time out for IZIGoRequest.
func (*IZIGoHTTPRequest) SetTransport ¶
func (b *IZIGoHTTPRequest) SetTransport(transport http.RoundTripper) *IZIGoHTTPRequest
SetTransport set the setting transport
func (*IZIGoHTTPRequest) SetUserAgent ¶
func (b *IZIGoHTTPRequest) SetUserAgent(useragent string) *IZIGoHTTPRequest
SetUserAgent sets User-Agent header field
func (*IZIGoHTTPRequest) Setting ¶
func (b *IZIGoHTTPRequest) Setting(setting IZIGoHTTPSettings) *IZIGoHTTPRequest
Setting Change request settings
func (*IZIGoHTTPRequest) String ¶
func (b *IZIGoHTTPRequest) String() (string, error)
String returns the body string in response. it calls Response inner.
func (*IZIGoHTTPRequest) ToFile ¶
func (b *IZIGoHTTPRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*IZIGoHTTPRequest) ToJSON ¶
func (b *IZIGoHTTPRequest) ToJSON(v interface{}) error
ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*IZIGoHTTPRequest) ToXML ¶
func (b *IZIGoHTTPRequest) ToXML(v interface{}) error
ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.
func (*IZIGoHTTPRequest) ToYAML ¶
func (b *IZIGoHTTPRequest) ToYAML(v interface{}) error
ToYAML returns the map that marshals from the body bytes as yaml in response . it calls Response inner.
func (*IZIGoHTTPRequest) XMLBody ¶
func (b *IZIGoHTTPRequest) XMLBody(obj interface{}) (*IZIGoHTTPRequest, error)
XMLBody adds request raw body encoding by XML.
func (*IZIGoHTTPRequest) YAMLBody ¶
func (b *IZIGoHTTPRequest) YAMLBody(obj interface{}) (*IZIGoHTTPRequest, error)
YAMLBody adds request raw body encoding by YAML.
type IZIGoHTTPSettings ¶
type IZIGoHTTPSettings struct { ShowDebug bool UserAgent string ConnectTimeout time.Duration ReadWriteTimeout time.Duration TLSClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) Transport http.RoundTripper CheckRedirect func(req *http.Request, via []*http.Request) error EnableCookie bool Gzip bool DumpBody bool Retries int // if set to -1 means will retry forever }
IZIGoHTTPSettings is the http.Client setting