v0.11.91 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 17 Imported by: 0




This section is empty.


This section is empty.


func SetDefaultSetting

func SetDefaultSetting(setting Settings)

Overwrite default settings

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.


type Request

type Request struct {
	// contains filtered or unexported fields

HttpRequest provides more useful methods for requesting one url than http.Request.

func Delete

func Delete(url string) *Request

Delete returns *Request DELETE method.

func Get

func Get(url string) *Request

Get returns *Request with GET method.

func Head(url string) *Request

Head returns *Request with HEAD method.

func Post

func Post(url string) *Request

Post returns *Request with POST method.

func Put

func Put(url string) *Request

Put returns *Request with PUT method.

func (*Request) Body

func (r *Request) Body(data interface{}) *Request

Body adds request raw body. it supports string and []byte.

func (*Request) Bytes

func (r *Request) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*Request) Debug

func (r *Request) Debug(isdebug bool) *Request

Debug sets show debug or not when executing request.

func (*Request) Header

func (r *Request) Header(key, value string) *Request

Header add header item string in request.

func (*Request) Headers

func (r *Request) Headers() http.Header

func (*Request) Param

func (r *Request) Param(key, value string) *Request

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*Request) PostFile

func (r *Request) PostFile(formname, filename string) *Request

func (*Request) Response

func (r *Request) Response() (*http.Response, error)

Response executes request client gets response mannually.

func (*Request) SetBasicAuth

func (r *Request) SetBasicAuth(username, password string) *Request

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*Request) SetCookie

func (r *Request) SetCookie(cookie *http.Cookie) *Request

SetCookie add cookie into request.

func (*Request) SetEnableCookie

func (r *Request) SetEnableCookie(enable bool) *Request

SetEnableCookie sets enable/disable cookiejar

func (*Request) SetProtocolVersion

func (r *Request) SetProtocolVersion(vers string) *Request

Set the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*Request) SetProxy

func (r *Request) SetProxy(proxy func(*http.Request) (*url.URL, error)) *Request

Set http proxy example:

func(req *http.Request) (*url.URL, error) {
	u, _ := url.ParseRequestURI("")
	return u, nil

func (*Request) SetTLSClientConfig

func (r *Request) SetTLSClientConfig(config *tls.Config) *Request

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*Request) SetTimeout

func (r *Request) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Request

SetTimeout sets connect time out and read-write time out for Request.

func (*Request) SetTransport

func (r *Request) SetTransport(transport http.RoundTripper) *Request

Set transport to

func (*Request) SetUserAgent

func (r *Request) SetUserAgent(useragent string) *Request

SetUserAgent sets User-Agent header field

func (*Request) Setting

func (r *Request) Setting(setting Settings) *Request

Change request settings

func (*Request) String

func (r *Request) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*Request) ToFile

func (r *Request) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*Request) ToJson

func (r *Request) ToJson(v interface{}) error

ToJson returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*Request) ToXml

func (r *Request) ToXml(v interface{}) error

ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type Settings

type Settings struct {
	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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL