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