Documentation ¶
Overview ¶
The code has been taken from https://github.com/valyala/fasthttp/pull/526 originally.
Index ¶
- Variables
- func ReleaseCookieJar(c *CookieJar)
- func ReleaseFile(f *File)
- func ReleaseRequest(req *Request)
- func ReleaseResponse(resp *Response)
- func Replace(c *Client) func()
- func SetValWithStruct(p WithStruct, tagName string, v any)
- type Client
- func (c *Client) AddHeader(key, val string) *Client
- func (c *Client) AddHeaders(h map[string][]string) *Client
- func (c *Client) AddParam(key, val string) *Client
- func (c *Client) AddParams(m map[string][]string) *Client
- func (c *Client) AddRequestHook(h ...RequestHook) *Client
- func (c *Client) AddResponseHook(h ...ResponseHook) *Client
- func (c *Client) BaseURL() string
- func (c *Client) Cookie(key string) string
- func (c *Client) Custom(url, method string, cfg ...Config) (*Response, error)
- func (c *Client) Debug() *Client
- func (c *Client) DelCookies(key ...string) *Client
- func (c *Client) DelParams(key ...string) *Client
- func (c *Client) DelPathParams(key ...string) *Client
- func (c *Client) Delete(url string, cfg ...Config) (*Response, error)
- func (c *Client) DisableDebug() *Client
- func (c *Client) Get(url string, cfg ...Config) (*Response, error)
- func (c *Client) Head(url string, cfg ...Config) (*Response, error)
- func (c *Client) Header(key string) []string
- func (c *Client) JSONMarshal() utils.JSONMarshal
- func (c *Client) JSONUnmarshal() utils.JSONUnmarshal
- func (c *Client) Logger() log.CommonLogger
- func (c *Client) Options(url string, cfg ...Config) (*Response, error)
- func (c *Client) Param(key string) []string
- func (c *Client) Patch(url string, cfg ...Config) (*Response, error)
- func (c *Client) PathParam(key string) string
- func (c *Client) Post(url string, cfg ...Config) (*Response, error)
- func (c *Client) Put(url string, cfg ...Config) (*Response, error)
- func (c *Client) R() *Request
- func (c *Client) RequestHook() []RequestHook
- func (c *Client) Reset()
- func (c *Client) ResponseHook() []ResponseHook
- func (c *Client) RetryConfig() *RetryConfig
- func (c *Client) SetBaseURL(url string) *Client
- func (c *Client) SetCertificates(certs ...tls.Certificate) *Client
- func (c *Client) SetCookie(key, val string) *Client
- func (c *Client) SetCookieJar(cookieJar *CookieJar) *Client
- func (c *Client) SetCookies(m map[string]string) *Client
- func (c *Client) SetCookiesWithStruct(v any) *Client
- func (c *Client) SetDial(dial fasthttp.DialFunc) *Client
- func (c *Client) SetHeader(key, val string) *Client
- func (c *Client) SetHeaders(h map[string]string) *Client
- func (c *Client) SetJSONMarshal(f utils.JSONMarshal) *Client
- func (c *Client) SetJSONUnmarshal(f utils.JSONUnmarshal) *Client
- func (c *Client) SetLogger(logger log.CommonLogger) *Client
- func (c *Client) SetParam(key, val string) *Client
- func (c *Client) SetParams(m map[string]string) *Client
- func (c *Client) SetParamsWithStruct(v any) *Client
- func (c *Client) SetPathParam(key, val string) *Client
- func (c *Client) SetPathParams(m map[string]string) *Client
- func (c *Client) SetPathParamsWithStruct(v any) *Client
- func (c *Client) SetProxyURL(proxyURL string) error
- func (c *Client) SetReferer(r string) *Client
- func (c *Client) SetRetryConfig(config *RetryConfig) *Client
- func (c *Client) SetRootCertificate(path string) *Client
- func (c *Client) SetRootCertificateFromString(pem string) *Client
- func (c *Client) SetTLSConfig(config *tls.Config) *Client
- func (c *Client) SetTimeout(t time.Duration) *Client
- func (c *Client) SetUserAgent(ua string) *Client
- func (c *Client) SetXMLMarshal(f utils.XMLMarshal) *Client
- func (c *Client) SetXMLUnmarshal(f utils.XMLUnmarshal) *Client
- func (c *Client) TLSConfig() *tls.Config
- func (c *Client) XMLMarshal() utils.XMLMarshal
- func (c *Client) XMLUnmarshal() utils.XMLUnmarshal
- type Config
- type Cookie
- func (c Cookie) Add(key, val string)
- func (c Cookie) Del(key string)
- func (c Cookie) DelCookies(key ...string)
- func (c Cookie) Reset()
- func (c Cookie) SetCookie(key, val string)
- func (c Cookie) SetCookies(m map[string]string)
- func (c Cookie) SetCookiesWithStruct(v any)
- func (c Cookie) VisitAll(f func(key, val string))
- type CookieJar
- func (cj *CookieJar) Get(uri *fasthttp.URI) []*fasthttp.Cookie
- func (cj *CookieJar) Release()
- func (cj *CookieJar) Set(uri *fasthttp.URI, cookies ...*fasthttp.Cookie)
- func (cj *CookieJar) SetByHost(host []byte, cookies ...*fasthttp.Cookie)
- func (cj *CookieJar) SetKeyValue(host, key, value string)
- func (cj *CookieJar) SetKeyValueBytes(host string, key, value []byte)
- type File
- type FormData
- func (f *FormData) AddData(key, val string)
- func (f *FormData) AddDatas(m map[string][]string)
- func (f *FormData) DelDatas(key ...string)
- func (f *FormData) Reset()
- func (f *FormData) SetData(key, val string)
- func (f *FormData) SetDatas(m map[string]string)
- func (f *FormData) SetDatasWithStruct(v any)
- type Header
- type PathParam
- func (p PathParam) Add(key, val string)
- func (p PathParam) Del(key string)
- func (p PathParam) DelParams(key ...string)
- func (p PathParam) Reset()
- func (p PathParam) SetParam(key, val string)
- func (p PathParam) SetParams(m map[string]string)
- func (p PathParam) SetParamsWithStruct(v any)
- func (p PathParam) VisitAll(f func(key, val string))
- type QueryParam
- type Request
- func (r *Request) AddFile(path string) *Request
- func (r *Request) AddFileWithReader(name string, reader io.ReadCloser) *Request
- func (r *Request) AddFiles(files ...*File) *Request
- func (r *Request) AddFormData(key, val string) *Request
- func (r *Request) AddFormDatas(m map[string][]string) *Request
- func (r *Request) AddHeader(key, val string) *Request
- func (r *Request) AddHeaders(h map[string][]string) *Request
- func (r *Request) AddParam(key, val string) *Request
- func (r *Request) AddParams(m map[string][]string) *Request
- func (r *Request) Boundary() string
- func (r *Request) Client() *Client
- func (r *Request) Context() context.Context
- func (r *Request) Cookie(key string) string
- func (r *Request) Custom(url, method string) (*Response, error)
- func (r *Request) DelCookies(key ...string) *Request
- func (r *Request) DelFormDatas(key ...string) *Request
- func (r *Request) DelParams(key ...string) *Request
- func (r *Request) DelPathParams(key ...string) *Request
- func (r *Request) Delete(url string) (*Response, error)
- func (r *Request) File(name string) *File
- func (r *Request) FileByPath(path string) *File
- func (r *Request) FormData(key string) []string
- func (r *Request) Get(url string) (*Response, error)
- func (r *Request) Head(url string) (*Response, error)
- func (r *Request) Header(key string) []string
- func (r *Request) MaxRedirects() int
- func (r *Request) Method() string
- func (r *Request) Options(url string) (*Response, error)
- func (r *Request) Param(key string) []string
- func (r *Request) Patch(url string) (*Response, error)
- func (r *Request) PathParam(key string) string
- func (r *Request) Post(url string) (*Response, error)
- func (r *Request) Put(url string) (*Response, error)
- func (r *Request) Referer() string
- func (r *Request) Reset()
- func (r *Request) ResetPathParams() *Request
- func (r *Request) Send() (*Response, error)
- func (r *Request) SetBoundary(b string) *Request
- func (r *Request) SetClient(c *Client) *Request
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetCookie(key, val string) *Request
- func (r *Request) SetCookies(m map[string]string) *Request
- func (r *Request) SetCookiesWithStruct(v any) *Request
- func (r *Request) SetFormData(key, val string) *Request
- func (r *Request) SetFormDatas(m map[string]string) *Request
- func (r *Request) SetFormDatasWithStruct(v any) *Request
- func (r *Request) SetHeader(key, val string) *Request
- func (r *Request) SetHeaders(h map[string]string) *Request
- func (r *Request) SetJSON(v any) *Request
- func (r *Request) SetMaxRedirects(count int) *Request
- func (r *Request) SetMethod(method string) *Request
- func (r *Request) SetParam(key, val string) *Request
- func (r *Request) SetParams(m map[string]string) *Request
- func (r *Request) SetParamsWithStruct(v any) *Request
- func (r *Request) SetPathParam(key, val string) *Request
- func (r *Request) SetPathParams(m map[string]string) *Request
- func (r *Request) SetPathParamsWithStruct(v any) *Request
- func (r *Request) SetRawBody(v []byte) *Request
- func (r *Request) SetReferer(referer string) *Request
- func (r *Request) SetTimeout(t time.Duration) *Request
- func (r *Request) SetURL(url string) *Request
- func (r *Request) SetUserAgent(ua string) *Request
- func (r *Request) SetXML(v any) *Request
- func (r *Request) Timeout() time.Duration
- func (r *Request) URL() string
- func (r *Request) UserAgent() string
- type RequestHook
- type Response
- func AcquireResponse() *Response
- func Delete(url string, cfg ...Config) (*Response, error)
- func Get(url string, cfg ...Config) (*Response, error)
- func Head(url string, cfg ...Config) (*Response, error)
- func Options(url string, cfg ...Config) (*Response, error)
- func Patch(url string, cfg ...Config) (*Response, error)
- func Post(url string, cfg ...Config) (*Response, error)
- func Put(url string, cfg ...Config) (*Response, error)
- func (r *Response) Body() []byte
- func (r *Response) Close()
- func (r *Response) Cookies() []*fasthttp.Cookie
- func (r *Response) Header(key string) string
- func (r *Response) JSON(v any) error
- func (r *Response) Protocol() string
- func (r *Response) Reset()
- func (r *Response) Save(v any) error
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) String() string
- func (r *Response) XML(v any) error
- type ResponseHook
- type RetryConfig
- type SetFileFunc
- type WithStruct
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidProxyURL = errors.New("invalid proxy url scheme") ErrFailedToAppendCert = errors.New("failed to append certificate") )
var ( ErrTimeoutOrCancel = errors.New("timeout or cancel") ErrURLFormat = errors.New("the url is a mistake") ErrNotSupportSchema = errors.New("the protocol is not support, only http or https") ErrFileNoName = errors.New("the file should have name") ErrBodyType = errors.New("the body type should be []byte") ErrNotSupportSaveMethod = errors.New("file path and io.Writer are supported") )
var ErrClientNil = errors.New("client can not be nil")
Functions ¶
func ReleaseCookieJar ¶
func ReleaseCookieJar(c *CookieJar)
ReleaseCookieJar returns CookieJar to the pool.
func ReleaseFile ¶
func ReleaseFile(f *File)
ReleaseFile returns the object acquired via AcquireFile to the pool.
Do not access the released File object, otherwise data races may occur.
func ReleaseRequest ¶
func ReleaseRequest(req *Request)
ReleaseRequest returns the object acquired via AcquireRequest to the pool.
Do not access the released Request object, otherwise data races may occur.
func ReleaseResponse ¶
func ReleaseResponse(resp *Response)
ReleaseResponse returns the object acquired via AcquireResponse to the pool.
Do not access the released Response object, otherwise data races may occur.
func Replace ¶
func Replace(c *Client) func()
Replace the defaultClient, the returned function can undo.
func SetValWithStruct ¶
func SetValWithStruct(p WithStruct, tagName string, v any)
SetValWithStruct Set some values using structs. `p` is a structure that implements the WithStruct interface, The field name can be specified by `tagName`. `v` is a struct include some data. Note: This method only supports simple types and nested structs are not currently supported.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
The Client is used to create a Fiber Client with client-level settings that apply to all requests raise from the client.
Fiber Client also provides an option to override or merge most of the client settings at the request.
func (*Client) AddHeader ¶
AddHeader method adds a single header field and its value in the client instance. These headers will be applied to all requests raised from this client instance. Also, it can be overridden at request level header options.
func (*Client) AddHeaders ¶
AddHeaders method adds multiple headers field and its values at one go in the client instance. These headers will be applied to all requests raised from this client instance. Also it can be overridden at request level headers options.
func (*Client) AddParam ¶
AddParam method adds a single query param field and its value in the client instance. These params will be applied to all requests raised from this client instance. Also, it can be overridden at request level param options.
func (*Client) AddParams ¶
AddParams method adds multiple query params field and its values at one go in the client instance. These params will be applied to all requests raised from this client instance. Also it can be overridden at request level params options.
func (*Client) AddRequestHook ¶
func (c *Client) AddRequestHook(h ...RequestHook) *Client
AddRequestHook Add user-defined request hooks.
func (*Client) AddResponseHook ¶
func (c *Client) AddResponseHook(h ...ResponseHook) *Client
AddResponseHook Add user-defined response hooks.
func (*Client) Cookie ¶
Cookie returns the cookie be set in request instance. if cookie doesn't exist, return empty string.
func (*Client) DelCookies ¶
DelCookies method deletes single or multiple cookies field and its values in client.
func (*Client) DelParams ¶
DelParams method deletes single or multiple params field and its values in client.
func (*Client) DelPathParams ¶
DelPathParams method deletes single or multiple path params field and its values in client.
func (*Client) DisableDebug ¶
DisableDebug disables log debug level output.
func (*Client) Header ¶
Header method returns header value via key, this method will visit all field in the header, then sort them.
func (*Client) JSONMarshal ¶
func (c *Client) JSONMarshal() utils.JSONMarshal
JSONMarshal returns json marshal function in Core.
func (*Client) JSONUnmarshal ¶
func (c *Client) JSONUnmarshal() utils.JSONUnmarshal
JSONUnmarshal returns json unmarshal function in Core.
func (*Client) Logger ¶
func (c *Client) Logger() log.CommonLogger
Logger returns logger instance of client.
func (*Client) Param ¶
Param method returns params value via key, this method will visit all field in the query param.
func (*Client) PathParam ¶
PathParam returns the path param be set in request instance. if path param doesn't exist, return empty string.
func (*Client) RequestHook ¶
func (c *Client) RequestHook() []RequestHook
RequestHook Request returns user-defined request hooks.
func (*Client) ResponseHook ¶
func (c *Client) ResponseHook() []ResponseHook
ResponseHook return user-define response hooks.
func (*Client) RetryConfig ¶
func (c *Client) RetryConfig() *RetryConfig
RetryConfig returns retry config in client.
func (*Client) SetBaseURL ¶
SetBaseURL Set baseUrl which is prefix of real url.
func (*Client) SetCertificates ¶
func (c *Client) SetCertificates(certs ...tls.Certificate) *Client
SetCertificates method sets client certificates into client.
func (*Client) SetCookie ¶
SetCookie method sets a single cookie field and its value in the client instance. These cookies will be applied to all requests raised from this client instance. Also it can be overridden at request level cookie options.
func (*Client) SetCookieJar ¶
SetCookieJar sets cookie jar in client instance.
func (*Client) SetCookies ¶
SetCookies method sets multiple cookies field and its values at one go in the client instance. These cookies will be applied to all requests raised from this client instance. Also it can be overridden at request level cookie options.
func (*Client) SetCookiesWithStruct ¶
SetCookiesWithStruct method sets multiple cookies field and its values at one go in the client instance. These cookies will be applied to all requests raised from this client instance. Also it can be overridden at request level cookies options.
func (*Client) SetHeader ¶
SetHeader method sets a single header field and its value in the client instance. These headers will be applied to all requests raised from this client instance. Also, it can be overridden at request level header options.
func (*Client) SetHeaders ¶
SetHeaders method sets multiple headers field and its values at one go in the client instance. These headers will be applied to all requests raised from this client instance. Also it can be overridden at request level headers options.
func (*Client) SetJSONMarshal ¶
SetJSONMarshal sets the JSON encoder.
func (*Client) SetJSONUnmarshal ¶
Set json decoder.
func (*Client) SetLogger ¶
func (c *Client) SetLogger(logger log.CommonLogger) *Client
SetLogger sets logger instance in client.
func (*Client) SetParam ¶
SetParam method sets a single query param field and its value in the client instance. These params will be applied to all requests raised from this client instance. Also, it can be overridden at request level param options.
func (*Client) SetParams ¶
SetParams method sets multiple params field and its values at one go in the client instance. These params will be applied to all requests raised from this client instance. Also it can be overridden at request level params options.
func (*Client) SetParamsWithStruct ¶
SetParamsWithStruct method sets multiple params field and its values at one go in the client instance. These params will be applied to all requests raised from this client instance. Also it can be overridden at request level params options.
func (*Client) SetPathParam ¶
SetPathParam method sets a single path param field and its value in the client instance. These path params will be applied to all requests raised from this client instance. Also it can be overridden at request level path params options.
func (*Client) SetPathParams ¶
SetPathParams method sets multiple path params field and its values at one go in the client instance. These path params will be applied to all requests raised from this client instance. Also it can be overridden at request level path params options.
func (*Client) SetPathParamsWithStruct ¶
SetPathParamsWithStruct method sets multiple path params field and its values at one go in the client instance. These path params will be applied to all requests raised from this client instance. Also it can be overridden at request level path params options.
func (*Client) SetProxyURL ¶
SetProxyURL sets proxy url in client. It will apply via core to hostclient.
func (*Client) SetReferer ¶
SetReferer method sets referer field and its value in the client instance. This referer will be applied to all requests raised from this client instance. Also it can be overridden at request level referer options.
func (*Client) SetRetryConfig ¶
func (c *Client) SetRetryConfig(config *RetryConfig) *Client
SetRetryConfig sets retry config in client which is impl by addon/retry package.
func (*Client) SetRootCertificate ¶
SetRootCertificate adds one or more root certificates into client.
func (*Client) SetRootCertificateFromString ¶
SetRootCertificateFromString method adds one or more root certificates into client.
func (*Client) SetTLSConfig ¶
SetTLSConfig sets tlsConfig in client.
func (*Client) SetTimeout ¶
SetTimeout method sets timeout val in client instance. This value will be applied to all requests raised from this client instance. Also, it can be overridden at request level timeout options.
func (*Client) SetUserAgent ¶
SetUserAgent method sets userAgent field and its value in the client instance. This ua will be applied to all requests raised from this client instance. Also it can be overridden at request level ua options.
func (*Client) SetXMLMarshal ¶
SetXMLMarshal Set xml encoder.
func (*Client) SetXMLUnmarshal ¶
SetXMLUnmarshal Set xml decoder.
func (*Client) TLSConfig ¶
TLSConfig returns tlsConfig in client. If client don't have tlsConfig, this function will init it.
func (*Client) XMLMarshal ¶
func (c *Client) XMLMarshal() utils.XMLMarshal
XMLMarshal returns xml marshal function in Core.
func (*Client) XMLUnmarshal ¶
func (c *Client) XMLUnmarshal() utils.XMLUnmarshal
XMLUnmarshal returns xml unmarshal function in Core.
type Config ¶
type Config struct { Ctx context.Context //nolint:containedctx // It's needed to be stored in the config. UserAgent string Referer string Header map[string]string Param map[string]string Cookie map[string]string PathParam map[string]string Timeout time.Duration MaxRedirects int Body any FormData map[string]string File []*File }
Config for easy to set the request parameters, it should be noted that when setting the request body will use JSON as the default serialization mechanism, while the priority of Body is higher than FormData, and the priority of FormData is higher than File.
type Cookie ¶
Cookie is a map which to store the cookies.
func (Cookie) DelCookies ¶
DelCookies method deletes multiple val in Cookie.
func (Cookie) SetCookies ¶
SetCookies method sets multiple val in Cookie.
func (Cookie) SetCookiesWithStruct ¶
SetCookiesWithStruct method sets multiple val in Cookie via a struct.
type CookieJar ¶
type CookieJar struct {
// contains filtered or unexported fields
}
CookieJar manages cookie storage. It is used by the client to store cookies.
func AcquireCookieJar ¶
func AcquireCookieJar() *CookieJar
AcquireCookieJar returns an empty CookieJar object from pool.
func (*CookieJar) Get ¶
Get returns the cookies stored from a specific domain. If there were no cookies related with host returned slice will be nil.
CookieJar keeps a copy of the cookies, so the returned cookies can be released safely.
func (*CookieJar) Set ¶
Set sets cookies for a specific host. The host is get from uri.Host(). If the cookie key already exists it will be replaced by the new cookie value.
CookieJar keeps a copy of the cookies, so the parsed cookies can be released safely.
func (*CookieJar) SetByHost ¶
SetByHost sets cookies for a specific host. If the cookie key already exists it will be replaced by the new cookie value.
CookieJar keeps a copy of the cookies, so the parsed cookies can be released safely.
func (*CookieJar) SetKeyValue ¶
SetKeyValue sets a cookie by key and value for a specific host.
This function prevents extra allocations by making repeated cookies not being duplicated.
func (*CookieJar) SetKeyValueBytes ¶
SetKeyValueBytes sets a cookie by key and value for a specific host.
This function prevents extra allocations by making repeated cookies not being duplicated.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a struct which support send files via request.
func AcquireFile ¶
func AcquireFile(setter ...SetFileFunc) *File
AcquireFile returns an File object from the pool. And you can set field in the File with SetFileFunc.
The returned file may be returned to the pool with ReleaseFile when no longer needed. This allows reducing GC load.
func (*File) SetFieldName ¶
SetFieldName method sets key of file in the body.
func (*File) SetReader ¶
func (f *File) SetReader(r io.ReadCloser)
SetReader method can receive a io.ReadCloser which will be closed in parserBody hook.
type FormData ¶
FormData is a wrapper of fasthttp.Args, and it is used for url encode body and file body.
func (*FormData) SetDatasWithStruct ¶
SetDatasWithStruct method supports set multiple fields via a struct.
type Header ¶
type Header struct {
*fasthttp.RequestHeader
}
Header is a wrapper which wrap http.Header, the header in client and request will store in it.
func (*Header) AddHeaders ¶
AddHeaders receives a map and add each value to header.
func (*Header) PeekMultiple ¶
PeekMultiple methods returns multiple field in header with same key.
func (*Header) SetHeaders ¶
SetHeaders will override all headers.
type PathParam ¶
PathParam is a map which to store path params.
func (PathParam) SetParamsWithStruct ¶
SetParamsWithStruct method sets multiple val in PathParam via a struct.
type QueryParam ¶
QueryParam is a wrapper which wrap url.Values, the query string and formdata in client and request will store in it.
func (*QueryParam) AddParams ¶
func (p *QueryParam) AddParams(r map[string][]string)
AddParams receive a map and add each value to param.
func (*QueryParam) SetParams ¶
func (p *QueryParam) SetParams(r map[string]string)
SetParams will override all params.
func (*QueryParam) SetParamsWithStruct ¶
func (p *QueryParam) SetParamsWithStruct(v any)
SetParamsWithStruct will override all params with struct or pointer of struct. Now nested structs are not currently supported.
type Request ¶
Request is a struct which contains the request data.
func AcquireRequest ¶
func AcquireRequest() *Request
AcquireRequest returns an empty request object from the pool.
The returned request may be returned to the pool with ReleaseRequest when no longer needed. This allows reducing GC load.
func (*Request) AddFile ¶
AddFile method adds single file field and its value in the request instance via file path.
func (*Request) AddFileWithReader ¶
func (r *Request) AddFileWithReader(name string, reader io.ReadCloser) *Request
AddFileWithReader method adds single field and its value in the request instance via reader.
func (*Request) AddFiles ¶
AddFiles method adds multiple file fields and its value in the request instance via File instance.
func (*Request) AddFormData ¶
AddFormData method adds a single form data field and its value in the request instance.
func (*Request) AddFormDatas ¶
AddFormDatas method adds multiple form data fields and its values in the request instance.
func (*Request) AddHeader ¶
AddHeader method adds a single header field and its value in the request instance.
func (*Request) AddHeaders ¶
AddHeaders method adds multiple header fields and its values at one go in the request instance.
func (*Request) AddParam ¶
AddParam method adds a single param field and its value in the request instance.
func (*Request) AddParams ¶
AddParams method adds multiple param fields and its values at one go in the request instance.
func (*Request) Context ¶
Context returns the Context if its already set in request otherwise it creates new one using `context.Background()`.
func (*Request) Cookie ¶
Cookie returns the cookie be set in request instance. if cookie doesn't exist, return empty string.
func (*Request) DelCookies ¶
DelCookies method deletes single or multiple cookie fields ant its values.
func (*Request) DelFormDatas ¶
DelFormDatas method deletes multiple form data fields and its value in the request instance.
func (*Request) DelParams ¶
DelParams method deletes single or multiple param fields ant its values.
func (*Request) DelPathParams ¶
DelPathParams method deletes single or multiple path param fields ant its values.
func (*Request) File ¶
File returns file ptr store in request obj by name. If name field is empty, it will try to match path.
func (*Request) FileByPath ¶
FileByPath returns file ptr store in request obj by path.
func (*Request) FormData ¶
FormData method returns form data value via key, this method will visit all field in the form data.
func (*Request) Header ¶
Header method returns header value via key, this method will visit all field in the header.
func (*Request) MaxRedirects ¶
MaxRedirects returns the max redirects count in request.
func (*Request) Param ¶
Param method returns params value via key, this method will visit all field in the query param.
func (*Request) PathParam ¶
PathParam returns the path param be set in request instance. if path param doesn't exist, return empty string.
func (*Request) Reset ¶
func (r *Request) Reset()
Reset clear Request object, used by ReleaseRequest method.
func (*Request) ResetPathParams ¶
ResetPathParams deletes all path params.
func (*Request) SetBoundary ¶
SetBoundary method sets multipart boundary.
func (*Request) SetContext ¶
SetContext sets the context.Context for current Request. It allows to interrupt the request execution if ctx.Done() channel is closed. See https://blog.golang.org/context article and the "context" package documentation.
func (*Request) SetCookie ¶
SetCookie method sets a single cookie field and its value in the request instance. It will override cookie which set in client instance.
func (*Request) SetCookies ¶
SetCookies method sets multiple cookie fields and its values at one go in the request instance. It will override cookie which set in client instance.
func (*Request) SetCookiesWithStruct ¶
SetCookiesWithStruct method sets multiple cookie fields and its values at one go in the request instance. It will override cookie which set in client instance.
func (*Request) SetFormData ¶
SetFormData method sets a single form data field and its value in the request instance.
func (*Request) SetFormDatas ¶
SetFormDatas method sets multiple form data fields and its values in the request instance.
func (*Request) SetFormDatasWithStruct ¶
SetFormDatasWithStruct method sets multiple form data fields and its values in the request instance via struct.
func (*Request) SetHeader ¶
SetHeader method sets a single header field and its value in the request instance. It will override header which has been set in client instance.
func (*Request) SetHeaders ¶
SetHeaders method sets multiple header fields and its values at one go in the request instance. It will override header which has been set in client instance.
func (*Request) SetMaxRedirects ¶
SetMaxRedirects method sets the maximum number of redirects at one go in the request instance. It will override max redirect which set in client instance.
func (*Request) SetMethod ¶
SetMethod will set method for Request object, user should use request method to set method.
func (*Request) SetParam ¶
SetParam method sets a single param field and its value in the request instance. It will override param which has been set in client instance.
func (*Request) SetParams ¶
SetParams method sets multiple param fields and its values at one go in the request instance. It will override param which has been set in client instance.
func (*Request) SetParamsWithStruct ¶
SetParamsWithStruct method sets multiple param fields and its values at one go in the request instance. It will override param which has been set in client instance.
func (*Request) SetPathParam ¶
SetPathParam method sets a single path param field and its value in the request instance. It will override path param which set in client instance.
func (*Request) SetPathParams ¶
SetPathParams method sets multiple path param fields and its values at one go in the request instance. It will override path param which set in client instance.
func (*Request) SetPathParamsWithStruct ¶
SetPathParamsWithStruct method sets multiple path param fields and its values at one go in the request instance. It will override path param which set in client instance.
func (*Request) SetRawBody ¶
SetRawBody method sets body with raw data in request.
func (*Request) SetReferer ¶
SetReferer method sets referer in request. It will override referer which set in client instance.
func (*Request) SetTimeout ¶
SetTimeout method sets timeout field and its values at one go in the request instance. It will override timeout which set in client instance.
func (*Request) SetUserAgent ¶
SetUserAgent method sets user agent in request. It will override user agent which has been set in client instance.
type RequestHook ¶
RequestHook is a function that receives Agent and Request, it can change the data in Request and Agent.
Called before a request is sent.
type Response ¶
Response is the result of a request. This object is used to access the response data.
func AcquireResponse ¶
func AcquireResponse() *Response
AcquireResponse returns an empty response object from the pool.
The returned response may be returned to the pool with ReleaseResponse when no longer needed. This allows reducing GC load.
func (*Response) Close ¶
func (r *Response) Close()
Close method will release Request object and Response object, after call Close please don't use these object.
func (*Response) Protocol ¶
Protocol method returns the HTTP response protocol used for the request.
func (*Response) StatusCode ¶
StatusCode method returns the HTTP status code for the executed request.
type ResponseHook ¶
ResponseHook is a function that receives Agent, Response and Request, it can change the data is Response or deal with some effects.
Called after a response has been received.
type RetryConfig ¶
RetryConfig is an alias for config in the `addon/retry` package.
type SetFileFunc ¶
type SetFileFunc func(f *File)
SetFileFunc The methods as follows is used by AcquireFile method. You can set file field via these method.
func SetFileFieldName ¶
func SetFileFieldName(p string) SetFileFunc
SetFileFieldName method sets key of file in the body.
func SetFileReader ¶
func SetFileReader(r io.ReadCloser) SetFileFunc
SetFileReader method can receive a io.ReadCloser
type WithStruct ¶
WithStruct Implementing this interface allows data to be stored from a struct via reflect.