Documentation ¶
Overview ¶
Usage:
import "github.com/CloudWise-OpenSource/GoCrab/Libs/httplib"
b := httplib.Post("http://GoCrab.me/") b.Param("username","Neeke") 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)
Index ¶
- func SetDefaultSetting(setting GoCrabHttpSettings)
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- type GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Body(data interface{}) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Bytes() ([]byte, error)
- func (b *GoCrabHttpRequest) Debug(isdebug bool) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Header(key, value string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Param(key, value string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) PostFile(formname, filename string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Response() (*http.Response, error)
- func (b *GoCrabHttpRequest) SetBasicAuth(username, password string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetCompress(compress string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetCookie(cookie *http.Cookie) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetEnableCookie(enable bool) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetProtocolVersion(vers string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetTLSClientConfig(config *tls.Config) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetTransport(transport http.RoundTripper) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) SetUserAgent(useragent string) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Setting(setting GoCrabHttpSettings) *GoCrabHttpRequest
- func (b *GoCrabHttpRequest) Status() (int, error)
- func (b *GoCrabHttpRequest) String() (string, error)
- func (b *GoCrabHttpRequest) ToFile(filename string) error
- func (b *GoCrabHttpRequest) ToJson(v interface{}) error
- func (b *GoCrabHttpRequest) ToXml(v interface{}) error
- type GoCrabHttpSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultSetting ¶
func SetDefaultSetting(setting GoCrabHttpSettings)
Overwrite default settings
Types ¶
type GoCrabHttpRequest ¶
type GoCrabHttpRequest struct {
// contains filtered or unexported fields
}
GoCrabHttpRequest provides more useful methods for requesting one url than http.Request.
func Delete ¶
func Delete(url string) *GoCrabHttpRequest
Delete returns *GoCrabHttpRequest DELETE method.
func Head ¶
func Head(url string) *GoCrabHttpRequest
Head returns *GoCrabHttpRequest with HEAD method.
func Post ¶
func Post(url string) *GoCrabHttpRequest
Post returns *GoCrabHttpRequest with POST method.
func (*GoCrabHttpRequest) Body ¶
func (b *GoCrabHttpRequest) Body(data interface{}) *GoCrabHttpRequest
Body adds request raw body. it supports string and []byte.
func (*GoCrabHttpRequest) Bytes ¶
func (b *GoCrabHttpRequest) Bytes() ([]byte, error)
Bytes returns the body []byte in response. it calls Response inner.
func (*GoCrabHttpRequest) Debug ¶
func (b *GoCrabHttpRequest) Debug(isdebug bool) *GoCrabHttpRequest
Debug sets show debug or not when executing request.
func (*GoCrabHttpRequest) Header ¶
func (b *GoCrabHttpRequest) Header(key, value string) *GoCrabHttpRequest
Header add header item string in request.
func (*GoCrabHttpRequest) Param ¶
func (b *GoCrabHttpRequest) Param(key, value string) *GoCrabHttpRequest
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*GoCrabHttpRequest) PostFile ¶
func (b *GoCrabHttpRequest) PostFile(formname, filename string) *GoCrabHttpRequest
func (*GoCrabHttpRequest) Response ¶
func (b *GoCrabHttpRequest) Response() (*http.Response, error)
Response executes request client gets response mannually.
func (*GoCrabHttpRequest) SetBasicAuth ¶
func (b *GoCrabHttpRequest) SetBasicAuth(username, password string) *GoCrabHttpRequest
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*GoCrabHttpRequest) SetCompress ¶
func (b *GoCrabHttpRequest) SetCompress(compress string) *GoCrabHttpRequest
func (*GoCrabHttpRequest) SetCookie ¶
func (b *GoCrabHttpRequest) SetCookie(cookie *http.Cookie) *GoCrabHttpRequest
SetCookie add cookie into request.
func (*GoCrabHttpRequest) SetEnableCookie ¶
func (b *GoCrabHttpRequest) SetEnableCookie(enable bool) *GoCrabHttpRequest
SetEnableCookie sets enable/disable cookiejar
func (*GoCrabHttpRequest) SetProtocolVersion ¶
func (b *GoCrabHttpRequest) SetProtocolVersion(vers string) *GoCrabHttpRequest
Set the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*GoCrabHttpRequest) SetProxy ¶
func (b *GoCrabHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *GoCrabHttpRequest
Set http proxy example:
func(req *http.Request) (*url.URL, error) { u, _ := url.ParseRequestURI("http://127.0.0.1:8118") return u, nil }
func (*GoCrabHttpRequest) SetTLSClientConfig ¶
func (b *GoCrabHttpRequest) SetTLSClientConfig(config *tls.Config) *GoCrabHttpRequest
SetTLSClientConfig sets tls connection configurations if visiting https url.
func (*GoCrabHttpRequest) SetTimeout ¶
func (b *GoCrabHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *GoCrabHttpRequest
SetTimeout sets connect time out and read-write time out for GoCrabRequest.
func (*GoCrabHttpRequest) SetTransport ¶
func (b *GoCrabHttpRequest) SetTransport(transport http.RoundTripper) *GoCrabHttpRequest
Set transport to
func (*GoCrabHttpRequest) SetUserAgent ¶
func (b *GoCrabHttpRequest) SetUserAgent(useragent string) *GoCrabHttpRequest
SetUserAgent sets User-Agent header field
func (*GoCrabHttpRequest) Setting ¶
func (b *GoCrabHttpRequest) Setting(setting GoCrabHttpSettings) *GoCrabHttpRequest
Change request settings
func (*GoCrabHttpRequest) String ¶
func (b *GoCrabHttpRequest) String() (string, error)
String returns the body string in response. it calls Response inner.
func (*GoCrabHttpRequest) ToFile ¶
func (b *GoCrabHttpRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*GoCrabHttpRequest) ToJson ¶
func (b *GoCrabHttpRequest) ToJson(v interface{}) error
ToJson returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*GoCrabHttpRequest) ToXml ¶
func (b *GoCrabHttpRequest) ToXml(v interface{}) error
ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.
type GoCrabHttpSettings ¶
type GoCrabHttpSettings struct { Compress string ShowDebug bool UserAgent string ConnectTimeout time.Duration ReadWriteTimeout time.Duration TlsClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) Transport http.RoundTripper EnableCookie bool }
GoCrabHttpSettings