Documentation ¶
Index ¶
- Constants
- func Reset()
- type Client
- func AcquireLock() *Client
- func BasicAuth(username, password string) *Client
- func BearerToken(token string) *Client
- func Connect(url string) *Client
- func Cookies(cookies ...*http.Cookie) *Client
- func Delete(url string) *Client
- func DisableKeepAlives() *Client
- func DisableProxy() *Client
- func DisableRedirect() *Client
- func DisableSession() *Client
- func DisableVerify() *Client
- func Files(files ...*File) *Client
- func Form(form Value) *Client
- func Get(url string) *Client
- func Head(url string) *Client
- func Headers(headers Value) *Client
- func Host(host string) *Client
- func JSON(data Data) *Client
- func New() *Client
- func Options(url string) *Client
- func Params(params Value) *Client
- func Patch(url string) *Client
- func Post(url string) *Client
- func Put(url string) *Client
- func Trace(url string) *Client
- func WithClientCertificates(certs ...tls.Certificate) *Client
- func WithContext(ctx context.Context) *Client
- func WithCookieJar(jar http.CookieJar) *Client
- func WithHTTPClient(httpClient *http.Client) *Client
- func WithProxy(url string) *Client
- func WithRedirectPolicy(policy func(req *http.Request, via []*http.Request) error) *Client
- func WithRootCA(pemFilePath string) *Client
- func WithTimeout(timeout time.Duration) *Client
- func WithTransport(transport http.RoundTripper) *Client
- func (c *Client) AcquireLock() *Client
- func (c *Client) BasicAuth(username, password string) *Client
- func (c *Client) BearerToken(token string) *Client
- func (c *Client) Connect(url string) *Client
- func (c *Client) Cookies(cookies ...*http.Cookie) *Client
- func (c *Client) Delete(url string) *Client
- func (c *Client) DisableKeepAlives() *Client
- func (c *Client) DisableProxy() *Client
- func (c *Client) DisableRedirect() *Client
- func (c *Client) DisableSession() *Client
- func (c *Client) DisableVerify() *Client
- func (c *Client) Files(files ...*File) *Client
- func (c *Client) Form(form Value) *Client
- func (c *Client) Get(url string) *Client
- func (c *Client) Head(url string) *Client
- func (c *Client) Headers(headers Value) *Client
- func (c *Client) Host(host string) *Client
- func (c *Client) JSON(data Data) *Client
- func (c *Client) Options(url string) *Client
- func (c *Client) Params(params Value) *Client
- func (c *Client) Patch(url string) *Client
- func (c *Client) Post(url string) *Client
- func (c *Client) Put(url string) *Client
- func (c *Client) Reset()
- func (c *Client) Send() *Response
- func (c *Client) Trace(url string) *Client
- func (c *Client) WithClientCertificates(certs ...tls.Certificate) *Client
- func (c *Client) WithContext(ctx context.Context) *Client
- func (c *Client) WithCookieJar(jar http.CookieJar) *Client
- func (c *Client) WithHTTPClient(httpClient *http.Client) *Client
- func (c *Client) WithProxy(url string) *Client
- func (c *Client) WithRedirectPolicy(policy func(req *http.Request, via []*http.Request) error) *Client
- func (c *Client) WithRootCA(pemFilePath string) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- func (c *Client) WithTransport(transport http.RoundTripper) *Client
- type Data
- type File
- type Response
- type Value
Constants ¶
const ( // Version of reqwest. Version = "0.1" // ContentType is the same as "Content-Type". ContentType = "Content-Type" // TypeForm is the same as "application/x-www-form-urlencoded". TypeForm = "application/x-www-form-urlencoded" // TypeJSON is the same as "application/json". TypeJSON = "application/json" // MethodGet represents GET HTTP method MethodGet = "GET" // MethodHead represents HEAD HTTP method MethodHead = "HEAD" // MethodPost represents POST HTTP method MethodPost = "POST" // MethodPut represents PUT HTTP method MethodPut = "PUT" // MethodPatch represents PATCH HTTP method MethodPatch = "PATCH" // MethodDelete represents DELETE HTTP method MethodDelete = "DELETE" // MethodConnect represents CONNECT HTTP method MethodConnect = "CONNECT" // MethodOptions represents OPTIONS HTTP method MethodOptions = "OPTIONS" // MethodTrace represents TRACE HTTP method MethodTrace = "TRACE" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines a reqwest client.
func AcquireLock ¶
func AcquireLock() *Client
AcquireLock locks the default reqwest client. Use reqwest across goroutines you must call AcquireLock for each request in the beginning, otherwise might cause data race. Don't forget it!
func BearerToken ¶
BearerToken sets bearer token of the default reqwest client.
func DisableKeepAlives ¶
func DisableKeepAlives() *Client
DisableKeepAlives disables HTTP keep-alives of the default reqwest client. HTTP keep-alives is enabled by default.
func DisableProxy ¶
func DisableProxy() *Client
DisableProxy lets the default reqwest client not use proxy. reqwest uses proxy from environment by default.
func DisableRedirect ¶
func DisableRedirect() *Client
DisableRedirect lets the default reqwest client not redirect HTTP requests. HTTP requests redirection is enabled by default.
func DisableSession ¶
func DisableSession() *Client
DisableSession lets the default reqwest client not use cookie jar. Session is enabled by default, reqwest use cookie jar to manage cookies automatically.
func DisableVerify ¶
func DisableVerify() *Client
DisableVerify lets the default reqwest client not verify the server's TLS certificate. TLS certificate verification is enabled by default.
func WithClientCertificates ¶
func WithClientCertificates(certs ...tls.Certificate) *Client
WithClientCertificates appends client certificates of the default reqwest client.
func WithContext ¶
WithContext sets HTTP requests context of the default reqwest client.
func WithCookieJar ¶
WithCookieJar changes cookie jar of the default reqwest client.
func WithHTTPClient ¶
WithHTTPClient changes HTTP client of the default reqwest client.
func WithRedirectPolicy ¶
WithRedirectPolicy changes redirection policy of the default reqwest client.
func WithRootCA ¶
WithRootCA appends root certificate authorities of the default reqwest client.
func WithTimeout ¶
WithTimeout changes timeout of the default reqwest client, zero means no timeout.
func WithTransport ¶
func WithTransport(transport http.RoundTripper) *Client
WithTransport changes transport of the default reqwest client.
func (*Client) AcquireLock ¶
AcquireLock locks c. Use reqwest across goroutines you must call AcquireLock for each request in the beginning, otherwise might cause data race. Don't forget it!
func (*Client) BearerToken ¶
BearerToken sets bearer token of c.
func (*Client) DisableKeepAlives ¶
DisableKeepAlives disables HTTP keep-alives of c. HTTP keep-alives is enabled by default.
func (*Client) DisableProxy ¶
DisableProxy lets c not use proxy. reqwest uses proxy from environment by default.
func (*Client) DisableRedirect ¶
DisableRedirect lets c not redirect HTTP requests. HTTP requests redirection is enabled by default.
func (*Client) DisableSession ¶
DisableSession lets c not use cookie jar. Session is enabled by default, reqwest use cookie jar to manage cookies automatically.
func (*Client) DisableVerify ¶
DisableVerify lets c not verify the server's TLS certificate. TLS certificate verification is enabled by default.
func (*Client) Reset ¶
func (c *Client) Reset()
Reset resets state of c so that other requests can acquire lock.
func (*Client) WithClientCertificates ¶
func (c *Client) WithClientCertificates(certs ...tls.Certificate) *Client
WithClientCertificates appends client certificates of c.
func (*Client) WithContext ¶
WithContext sets HTTP requests context of c.
func (*Client) WithCookieJar ¶
WithCookieJar sets cookie jar of c.
func (*Client) WithHTTPClient ¶
WithHTTPClient sets HTTP client of c.
func (*Client) WithRedirectPolicy ¶
func (c *Client) WithRedirectPolicy(policy func(req *http.Request, via []*http.Request) error) *Client
WithRedirectPolicy sets redirection policy of c.
func (*Client) WithRootCA ¶
WithRootCA appends root certificate authorities of c.
func (*Client) WithTimeout ¶
WithTimeout sets timeout of c, zero means no timeout.
func (*Client) WithTransport ¶
func (c *Client) WithTransport(transport http.RoundTripper) *Client
WithTransport sets transport of c.
type Data ¶
type Data map[string]interface{}
Data is the same as map[string]interface{}, used for JSON payload.
type File ¶
type File struct { // FieldName specifies the field name of the file you want to upload. FieldName string `json:"fieldname,omitempty"` // FileName specifies the file name of the file you want to upload. FileName string `json:"filename,omitempty"` // FilePath specifies the file path of the file you want to upload. FilePath string `json:"-"` }
File defines a multipart-data.
type Response ¶
type Response struct { // R specifies the original HTTP response. R *http.Response // Err specifies the potential error. Err error }
Response wraps the original HTTP response and the potential error.
func Send ¶
func Send() *Response
Send uses the default reqwest client to send the HTTP request and returns its response.
func (*Response) EnsureStatus2xx ¶
EnsureStatus2xx ensures the HTTP response's status code of r must be 2xx.
func (*Response) EnsureStatusOk ¶
EnsureStatusOk ensures the HTTP response's status code of r must be 200.
func (*Response) JSON ¶
JSON decodes the HTTP response body of r and unmarshals its JSON-encoded data into v.