Documentation ¶
Overview ¶
Package httplib is used as http.Client Usage:
import "github.com/flycash/beego-httplib/httplib"
b := httplib.Post("http://beego.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://beego.me/docs/module/httplib.md
Index ¶
- func SetDefaultSetting(setting BeegoHTTPSettings)
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- type BeegoHTTPRequest
- func (b *BeegoHTTPRequest) AddFilters(fcs ...FilterChain) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Bytes() ([]byte, error)
- func (b *BeegoHTTPRequest) Debug(isdebug bool) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) DoRequest() (resp *http.Response, err error)
- func (b *BeegoHTTPRequest) DoRequestWithCtx(ctx context.Context) (resp *http.Response, err error)
- func (b *BeegoHTTPRequest) DumpBody(isdump bool) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) DumpRequest() []byte
- func (b *BeegoHTTPRequest) GetRequest() *http.Request
- func (b *BeegoHTTPRequest) Header(key, value string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
- func (b *BeegoHTTPRequest) Param(key, value string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) PostFile(formname, filename string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Response() (*http.Response, error)
- func (b *BeegoHTTPRequest) Retries(times int) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) RetryDelay(delay time.Duration) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetBasicAuth(username, password string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetCookie(cookie *http.Cookie) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetEnableCookie(enable bool) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetFilters(fcs ...FilterChain) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetHost(host string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetProtocolVersion(vers string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetTLSClientConfig(config *tls.Config) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetTransport(transport http.RoundTripper) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) SetUserAgent(useragent string) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) Setting(setting BeegoHTTPSettings) *BeegoHTTPRequest
- func (b *BeegoHTTPRequest) String() (string, error)
- func (b *BeegoHTTPRequest) ToFile(filename string) error
- func (b *BeegoHTTPRequest) ToJSON(v interface{}) error
- func (b *BeegoHTTPRequest) ToXML(v interface{}) error
- func (b *BeegoHTTPRequest) ToYAML(v interface{}) error
- func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error)
- func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error)
- type BeegoHTTPSettings
- type Filter
- type FilterChain
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultSetting ¶
func SetDefaultSetting(setting BeegoHTTPSettings)
SetDefaultSetting overwrites default settings
Types ¶
type BeegoHTTPRequest ¶
type BeegoHTTPRequest struct {
// contains filtered or unexported fields
}
BeegoHTTPRequest provides more useful methods than http.Request for requesting a url.
func Delete ¶
func Delete(url string) *BeegoHTTPRequest
Delete returns *BeegoHttpRequest DELETE method.
func Head ¶
func Head(url string) *BeegoHTTPRequest
Head returns *BeegoHttpRequest with HEAD method.
func NewBeegoRequest ¶
func NewBeegoRequest(rawurl, method string) *BeegoHTTPRequest
NewBeegoRequest returns *BeegoHttpRequest with specific method
func Post ¶
func Post(url string) *BeegoHTTPRequest
Post returns *BeegoHttpRequest with POST method.
func (*BeegoHTTPRequest) AddFilters ¶
func (b *BeegoHTTPRequest) AddFilters(fcs ...FilterChain) *BeegoHTTPRequest
AddFilters adds filter
func (*BeegoHTTPRequest) Body ¶
func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest
Body adds request raw body. Supports string and []byte.
func (*BeegoHTTPRequest) Bytes ¶
func (b *BeegoHTTPRequest) Bytes() ([]byte, error)
Bytes returns the body []byte in response. Calls Response inner.
func (*BeegoHTTPRequest) Debug ¶
func (b *BeegoHTTPRequest) Debug(isdebug bool) *BeegoHTTPRequest
Debug sets show debug or not when executing request.
func (*BeegoHTTPRequest) DoRequest ¶
func (b *BeegoHTTPRequest) DoRequest() (resp *http.Response, err error)
DoRequest executes client.Do
func (*BeegoHTTPRequest) DoRequestWithCtx ¶
func (*BeegoHTTPRequest) DumpBody ¶
func (b *BeegoHTTPRequest) DumpBody(isdump bool) *BeegoHTTPRequest
DumpBody sets the DumbBody field
func (*BeegoHTTPRequest) DumpRequest ¶
func (b *BeegoHTTPRequest) DumpRequest() []byte
DumpRequest returns the DumpRequest
func (*BeegoHTTPRequest) GetRequest ¶
func (b *BeegoHTTPRequest) GetRequest() *http.Request
GetRequest returns the request object
func (*BeegoHTTPRequest) Header ¶
func (b *BeegoHTTPRequest) Header(key, value string) *BeegoHTTPRequest
Header adds header item string in request.
func (*BeegoHTTPRequest) JSONBody ¶
func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
JSONBody adds the request raw body encoded in JSON.
func (*BeegoHTTPRequest) Param ¶
func (b *BeegoHTTPRequest) Param(key, value string) *BeegoHTTPRequest
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*BeegoHTTPRequest) PostFile ¶
func (b *BeegoHTTPRequest) PostFile(formname, filename string) *BeegoHTTPRequest
PostFile adds a post file to the request
func (*BeegoHTTPRequest) Response ¶
func (b *BeegoHTTPRequest) Response() (*http.Response, error)
Response executes request client gets response manually.
func (*BeegoHTTPRequest) Retries ¶
func (b *BeegoHTTPRequest) Retries(times int) *BeegoHTTPRequest
Retries sets Retries times. default is 0 (never retry) -1 retry indefinitely (forever) Other numbers specify the exact retry amount
func (*BeegoHTTPRequest) RetryDelay ¶
func (b *BeegoHTTPRequest) RetryDelay(delay time.Duration) *BeegoHTTPRequest
RetryDelay sets the time to sleep between reconnection attempts
func (*BeegoHTTPRequest) SetBasicAuth ¶
func (b *BeegoHTTPRequest) SetBasicAuth(username, password string) *BeegoHTTPRequest
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*BeegoHTTPRequest) SetCheckRedirect ¶
func (b *BeegoHTTPRequest) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *BeegoHTTPRequest
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 (*BeegoHTTPRequest) SetCookie ¶
func (b *BeegoHTTPRequest) SetCookie(cookie *http.Cookie) *BeegoHTTPRequest
SetCookie adds a cookie to the request.
func (*BeegoHTTPRequest) SetEnableCookie ¶
func (b *BeegoHTTPRequest) SetEnableCookie(enable bool) *BeegoHTTPRequest
SetEnableCookie sets enable/disable cookiejar
func (*BeegoHTTPRequest) SetFilters ¶
func (b *BeegoHTTPRequest) SetFilters(fcs ...FilterChain) *BeegoHTTPRequest
SetFilters will use the filter as the invocation filters
func (*BeegoHTTPRequest) SetHost ¶
func (b *BeegoHTTPRequest) SetHost(host string) *BeegoHTTPRequest
SetHost set the request host
func (*BeegoHTTPRequest) SetProtocolVersion ¶
func (b *BeegoHTTPRequest) SetProtocolVersion(vers string) *BeegoHTTPRequest
SetProtocolVersion sets the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*BeegoHTTPRequest) SetProxy ¶
func (b *BeegoHTTPRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHTTPRequest
SetProxy sets the HTTP proxy example:
func(req *http.Request) (*url.URL, error) { u, _ := url.ParseRequestURI("http://127.0.0.1:8118") return u, nil }
func (*BeegoHTTPRequest) SetTLSClientConfig ¶
func (b *BeegoHTTPRequest) SetTLSClientConfig(config *tls.Config) *BeegoHTTPRequest
SetTLSClientConfig sets TLS connection configuration if visiting HTTPS url.
func (*BeegoHTTPRequest) SetTimeout ¶
func (b *BeegoHTTPRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHTTPRequest
SetTimeout sets connect time out and read-write time out for BeegoRequest.
func (*BeegoHTTPRequest) SetTransport ¶
func (b *BeegoHTTPRequest) SetTransport(transport http.RoundTripper) *BeegoHTTPRequest
SetTransport sets the transport field
func (*BeegoHTTPRequest) SetUserAgent ¶
func (b *BeegoHTTPRequest) SetUserAgent(useragent string) *BeegoHTTPRequest
SetUserAgent sets User-Agent header field
func (*BeegoHTTPRequest) Setting ¶
func (b *BeegoHTTPRequest) Setting(setting BeegoHTTPSettings) *BeegoHTTPRequest
Setting changes request settings
func (*BeegoHTTPRequest) String ¶
func (b *BeegoHTTPRequest) String() (string, error)
String returns the body string in response. Calls Response inner.
func (*BeegoHTTPRequest) ToFile ¶
func (b *BeegoHTTPRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. Calls Response inner.
func (*BeegoHTTPRequest) ToJSON ¶
func (b *BeegoHTTPRequest) ToJSON(v interface{}) error
ToJSON returns the map that marshals from the body bytes as json in response. Calls Response inner.
func (*BeegoHTTPRequest) ToXML ¶
func (b *BeegoHTTPRequest) ToXML(v interface{}) error
ToXML returns the map that marshals from the body bytes as xml in response . Calls Response inner.
func (*BeegoHTTPRequest) ToYAML ¶
func (b *BeegoHTTPRequest) ToYAML(v interface{}) error
ToYAML returns the map that marshals from the body bytes as yaml in response . Calls Response inner.
func (*BeegoHTTPRequest) XMLBody ¶
func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error)
XMLBody adds the request raw body encoded in XML.
func (*BeegoHTTPRequest) YAMLBody ¶
func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error)
YAMLBody adds the request raw body encoded in YAML.
type BeegoHTTPSettings ¶
type BeegoHTTPSettings 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 RetryDelay time.Duration FilterChains []FilterChain }
BeegoHTTPSettings is the http.Client setting