Documentation
¶
Overview ¶
The code was originally taken from https://github.com/valyala/fasthttp/pull/526.
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) CBORMarshal() utils.CBORMarshal
- func (c *Client) CBORUnmarshal() utils.CBORUnmarshal
- 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) SetCBORMarshal(f utils.CBORMarshal) *Client
- func (c *Client) SetCBORUnmarshal(f utils.CBORUnmarshal) *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) Add(key, val string)
- func (f *FormData) AddWithMap(m map[string][]string)
- func (f *FormData) DelData(key ...string)
- func (f *FormData) Keys() []string
- func (f *FormData) Reset()
- func (f *FormData) Set(key, val string)
- func (f *FormData) SetWithMap(m map[string]string)
- func (f *FormData) SetWithStruct(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) AddFormDataWithMap(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) AllFormData() iter.Seq2[string, []string]
- 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) Cookies() iter.Seq2[string, string]
- func (r *Request) Custom(url, method string) (*Response, error)
- func (r *Request) DelCookies(key ...string) *Request
- func (r *Request) DelFormData(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) Files() []*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) Headers() iter.Seq2[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) Params() iter.Seq2[string, []string]
- func (r *Request) Patch(url string) (*Response, error)
- func (r *Request) PathParam(key string) string
- func (r *Request) PathParams() iter.Seq2[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) SetCBOR(v any) *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) SetFormDataWithMap(m map[string]string) *Request
- func (r *Request) SetFormDataWithStruct(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) CBOR(v any) error
- func (r *Response) Close()
- func (r *Response) Cookies() []*fasthttp.Cookie
- func (r *Response) Header(key string) string
- func (r *Response) Headers() iter.Seq2[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 ( ErrTimeoutOrCancel = errors.New("timeout or cancel") ErrURLFormat = errors.New("the URL is incorrect") ErrNotSupportSchema = errors.New("protocol not supported; only http or https are allowed") ErrFileNoName = errors.New("the file should have a name") ErrBodyType = errors.New("the body type should be []byte") ErrNotSupportSaveMethod = errors.New("only file paths and io.Writer are supported") )
var ErrClientNil = errors.New("client cannot be nil")
var ErrFailedToAppendCert = errors.New("failed to append certificate")
Functions ¶
func ReleaseCookieJar ¶
func ReleaseCookieJar(c *CookieJar)
ReleaseCookieJar returns a CookieJar object to the pool.
func ReleaseFile ¶
func ReleaseFile(f *File)
ReleaseFile returns the File object to the pool. Do not use the released File afterward to avoid data races.
func ReleaseRequest ¶
func ReleaseRequest(req *Request)
ReleaseRequest returns the Request object to the pool. Do not use the released Request afterward to avoid data races.
func ReleaseResponse ¶
func ReleaseResponse(resp *Response)
ReleaseResponse returns the Response object to the pool. Do not use the released Response afterward to avoid data races.
func Replace ¶
func Replace(c *Client) func()
Replace replaces the defaultClient with a new one, returning a function to restore the old client.
func SetValWithStruct ¶
func SetValWithStruct(p WithStruct, tagName string, v any)
SetValWithStruct sets values using a struct. The struct's fields are examined via reflection. `p` is a type that implements WithStruct. `tagName` defines the struct tag to look for. `v` is the struct containing data.
Fields in `v` should be string, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, complex64, complex128 or bool. Arrays or slices are inserted sequentially with the same key. Other types are ignored.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to create a Velocity client with client-level settings that apply to all requests made by the client.
The Velocity client also provides an option to override or merge most of the client settings at the request level.
func NewWithClient ¶
NewWithClient creates and returns a new Client object from an existing fasthttp.Client.
func (*Client) AddHeader ¶
AddHeader adds a single header field and its value to the client. These headers apply to all requests.
func (*Client) AddHeaders ¶
AddHeaders adds multiple header fields and their values to the client.
func (*Client) AddParam ¶
AddParam adds a single query parameter and its value to the client. These params will be applied to all requests created from this client instance.
func (*Client) AddRequestHook ¶
func (c *Client) AddRequestHook(h ...RequestHook) *Client
AddRequestHook adds user-defined request hooks.
func (*Client) AddResponseHook ¶
func (c *Client) AddResponseHook(h ...ResponseHook) *Client
AddResponseHook adds user-defined response hooks.
func (*Client) CBORMarshal ¶
func (c *Client) CBORMarshal() utils.CBORMarshal
CBORMarshal returns the CBOR marshal function used by the client.
func (*Client) CBORUnmarshal ¶
func (c *Client) CBORUnmarshal() utils.CBORUnmarshal
CBORUnmarshal returns the CBOR unmarshal function used by the client.
func (*Client) Cookie ¶
Cookie returns the value of the specified cookie. Returns an empty string if it does not exist.
func (*Client) Custom ¶
Custom sends a request with a custom method to the specified URL, similar to axios.
func (*Client) DelCookies ¶
DelCookies deletes one or more cookies and their values from the client.
func (*Client) DelParams ¶
DelParams deletes one or more query parameters and their values from the client.
func (*Client) DelPathParams ¶
DelPathParams deletes one or more path parameters and their values from the client.
func (*Client) DisableDebug ¶
DisableDebug disables debug-level logging output.
func (*Client) JSONMarshal ¶
func (c *Client) JSONMarshal() utils.JSONMarshal
JSONMarshal returns the JSON marshal function used by the client.
func (*Client) JSONUnmarshal ¶
func (c *Client) JSONUnmarshal() utils.JSONUnmarshal
JSONUnmarshal returns the JSON unmarshal function used by the client.
func (*Client) Logger ¶
func (c *Client) Logger() log.CommonLogger
Logger returns the logger instance used by the client.
func (*Client) PathParam ¶
PathParam returns the value of the specified path parameter. Returns an empty string if it does not exist.
func (*Client) RequestHook ¶
func (c *Client) RequestHook() []RequestHook
RequestHook returns the user-defined request hooks.
func (*Client) Reset ¶
func (c *Client) Reset()
Reset resets the client to its default state, clearing most configurations.
func (*Client) ResponseHook ¶
func (c *Client) ResponseHook() []ResponseHook
ResponseHook returns the user-defined response hooks.
func (*Client) RetryConfig ¶
func (c *Client) RetryConfig() *RetryConfig
RetryConfig returns the current retry configuration.
func (*Client) SetBaseURL ¶
SetBaseURL sets the base URL prefix for all requests made by the client.
func (*Client) SetCBORMarshal ¶
func (c *Client) SetCBORMarshal(f utils.CBORMarshal) *Client
SetCBORMarshal sets the CBOR marshal function to use.
func (*Client) SetCBORUnmarshal ¶
func (c *Client) SetCBORUnmarshal(f utils.CBORUnmarshal) *Client
SetCBORUnmarshal sets the CBOR unmarshal function to use.
func (*Client) SetCertificates ¶
func (c *Client) SetCertificates(certs ...tls.Certificate) *Client
SetCertificates adds certificates to the client's TLS configuration.
func (*Client) SetCookieJar ¶
SetCookieJar sets the cookie jar for the client.
func (*Client) SetCookies ¶
SetCookies sets multiple cookies and their values in the client.
func (*Client) SetCookiesWithStruct ¶
SetCookiesWithStruct sets multiple cookies and their values using a struct.
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 created from this client instance. Also it can be overridden at request level headers options.
func (*Client) SetJSONMarshal ¶
func (c *Client) SetJSONMarshal(f utils.JSONMarshal) *Client
SetJSONMarshal sets the JSON marshal function to use.
func (*Client) SetJSONUnmarshal ¶
func (c *Client) SetJSONUnmarshal(f utils.JSONUnmarshal) *Client
SetJSONUnmarshal sets the JSON unmarshal function to use.
func (*Client) SetLogger ¶
func (c *Client) SetLogger(logger log.CommonLogger) *Client
SetLogger sets the logger instance used by the client.
func (*Client) SetParamsWithStruct ¶
SetParamsWithStruct sets multiple query parameters and their values using a struct.
func (*Client) SetPathParam ¶
SetPathParam sets a single path parameter and its value in the client.
func (*Client) SetPathParams ¶
SetPathParams sets multiple path parameters and their values in the client.
func (*Client) SetPathParamsWithStruct ¶
SetPathParamsWithStruct sets multiple path parameters and their values using a struct.
func (*Client) SetProxyURL ¶
SetProxyURL sets the proxy URL for the client. This affects all subsequent requests.
func (*Client) SetReferer ¶
SetReferer sets the Referer header for the client.
func (*Client) SetRetryConfig ¶
func (c *Client) SetRetryConfig(config *RetryConfig) *Client
SetRetryConfig sets the retry configuration for the client.
func (*Client) SetRootCertificate ¶
SetRootCertificate adds one or more root certificates to the client's TLS configuration.
func (*Client) SetRootCertificateFromString ¶
SetRootCertificateFromString adds one or more root certificates from a string to the client's TLS configuration.
func (*Client) SetTLSConfig ¶
SetTLSConfig sets the TLS configuration for the client.
func (*Client) SetTimeout ¶
SetTimeout sets the timeout value for the client. This applies to all requests unless overridden at the request level.
func (*Client) SetUserAgent ¶
SetUserAgent sets the User-Agent header for the client.
func (*Client) SetXMLMarshal ¶
func (c *Client) SetXMLMarshal(f utils.XMLMarshal) *Client
SetXMLMarshal sets the XML marshal function to use.
func (*Client) SetXMLUnmarshal ¶
func (c *Client) SetXMLUnmarshal(f utils.XMLUnmarshal) *Client
SetXMLUnmarshal sets the XML unmarshal function to use.
func (*Client) TLSConfig ¶
TLSConfig returns the client's TLS configuration. If none is set, it initializes a new one.
func (*Client) XMLMarshal ¶
func (c *Client) XMLMarshal() utils.XMLMarshal
XMLMarshal returns the XML marshal function used by the client.
func (*Client) XMLUnmarshal ¶
func (c *Client) XMLUnmarshal() utils.XMLUnmarshal
XMLUnmarshal returns the XML unmarshal function used by the client.
type Config ¶
type Config struct {
Ctx context.Context //nolint:containedctx // It's needed to be stored in the config.
Body any
Header map[string]string
Param map[string]string
Cookie map[string]string
PathParam map[string]string
FormData map[string]string
UserAgent string
Referer string
File []*File
Timeout time.Duration
MaxRedirects int
}
Config is used to easily set request parameters. Note that when setting a request body, JSON is used as the default serialization mechanism. The priority is: Body > FormData > File.
type Cookie ¶
Cookie is a map used to store cookies.
func (Cookie) DelCookies ¶
DelCookies deletes multiple cookies by keys.
func (Cookie) SetCookies ¶
SetCookies sets multiple cookies from a map.
func (Cookie) SetCookiesWithStruct ¶
SetCookiesWithStruct sets cookies from a struct. Nested structs are not currently supported.
type CookieJar ¶
type CookieJar struct {
// contains filtered or unexported fields
}
CookieJar manages cookie storage for the client. It stores cookies keyed by host.
func AcquireCookieJar ¶
func AcquireCookieJar() *CookieJar
AcquireCookieJar returns an empty CookieJar object from the pool.
func (*CookieJar) Get ¶
Get returns all cookies stored for a given URI. If there are no cookies for the provided host, the returned slice will be nil.
The CookieJar keeps its own copies of cookies, so it is safe to release the returned cookies after use.
func (*CookieJar) Release ¶
func (cj *CookieJar) Release()
Release releases all stored cookies. After this, the CookieJar is empty.
func (*CookieJar) Set ¶
Set stores the given cookies for the specified URI host. If a cookie key already exists, it will be replaced by the new cookie value.
CookieJar stores copies of the provided cookies, so they may be safely released after use.
func (*CookieJar) SetByHost ¶
SetByHost stores the given cookies for the specified host. If a cookie key already exists, it will be replaced by the new cookie value.
CookieJar stores copies of the provided cookies, so they may be safely released after use.
func (*CookieJar) SetKeyValue ¶
SetKeyValue sets a cookie for the specified host with the given key and value.
This function helps prevent extra allocations by avoiding duplication of repeated cookies.
func (*CookieJar) SetKeyValueBytes ¶
SetKeyValueBytes sets a cookie for the specified host using byte slices for the key and value.
This function helps prevent extra allocations by avoiding duplication of repeated cookies.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a file to be sent with the request.
func AcquireFile ¶
func AcquireFile(setter ...SetFileFunc) *File
AcquireFile returns a (pooled) File object and applies the provided SetFileFunc functions to it.
func (*File) SetFieldName ¶
SetFieldName sets the key associated with the file in the body.
func (*File) SetReader ¶
func (f *File) SetReader(r io.ReadCloser)
SetReader sets the file's reader, which will be closed in the parserBody hook.
type FormData ¶
FormData wraps fasthttp.Args for URL-encoded bodies and form data.
func (*FormData) AddWithMap ¶
AddWithMap adds multiple form fields from a map.
func (*FormData) SetWithMap ¶
SetWithMap sets multiple form fields from a map, overriding previously set values.
func (*FormData) SetWithStruct ¶
SetWithStruct sets multiple form fields from a struct. Nested structs are not currently supported.
type Header ¶
type Header struct {
*fasthttp.RequestHeader
}
Header wraps fasthttp.RequestHeader, storing headers for both client and request.
func (*Header) AddHeaders ¶
AddHeaders adds multiple headers from a map.
func (*Header) PeekMultiple ¶
PeekMultiple returns multiple values of a header field with the same key.
func (*Header) SetHeaders ¶
SetHeaders sets multiple headers from a map, overriding previously set values.
type PathParam ¶
PathParam is a map used to store path parameters.
func (PathParam) SetParamsWithStruct ¶
SetParamsWithStruct sets multiple path parameters from a struct. Nested structs are not currently supported.
type QueryParam ¶
QueryParam wraps fasthttp.Args for query parameters.
func (*QueryParam) AddParams ¶
func (p *QueryParam) AddParams(r map[string][]string)
AddParams adds multiple parameters from a map.
func (*QueryParam) Keys ¶
func (p *QueryParam) Keys() []string
Keys returns all keys from the query parameters.
func (*QueryParam) SetParams ¶
func (p *QueryParam) SetParams(r map[string]string)
SetParams sets multiple parameters from a map, overriding previously set values.
func (*QueryParam) SetParamsWithStruct ¶
func (p *QueryParam) SetParamsWithStruct(v any)
SetParamsWithStruct sets multiple parameters from a struct. Nested structs are not currently supported.
type Request ¶
Request contains all data related to an HTTP request.
func AcquireRequest ¶
func AcquireRequest() *Request
AcquireRequest returns a new (pooled) Request object.
func (*Request) AddFileWithReader ¶
func (r *Request) AddFileWithReader(name string, reader io.ReadCloser) *Request
AddFileWithReader adds a file using an io.ReadCloser.
func (*Request) AddFormData ¶
AddFormData adds a single form field and value to the Request.
func (*Request) AddFormDataWithMap ¶
AddFormDataWithMap adds multiple form fields and values to the Request.
func (*Request) AddHeaders ¶
AddHeaders adds multiple header fields and values at once.
func (*Request) AllFormData ¶
AllFormData returns an iterator over all form fields. Use maps.Collect() to gather them into a map if needed.
The returned values are only valid until the request object is released. Do not store references to returned values; make copies instead.
func (*Request) Context ¶
Context returns the context associated with the Request. If not set, a background context is returned.
func (*Request) Cookie ¶
Cookie returns the value of a named cookie. If the cookie does not exist, an empty string is returned.
func (*Request) Cookies ¶
Cookies returns an iterator over all cookies. Use maps.Collect() to gather them into a map if needed.
func (*Request) DelCookies ¶
DelCookies deletes one or more cookies.
func (*Request) DelFormData ¶
DelFormData deletes one or more form fields.
func (*Request) DelPathParams ¶
DelPathParams deletes one or more path parameters.
func (*Request) File ¶
File returns the file associated with the given name. If no name was provided during addition, it attempts to match by the file's base name.
func (*Request) FileByPath ¶
FileByPath returns the file associated with the given file path.
func (*Request) Files ¶
Files returns all files added to the Request.
The returned values are only valid until the request object is released. Do not store references to returned values; make copies instead.
func (*Request) Headers ¶
Headers returns an iterator over all headers in the Request. Use maps.Collect() to gather them into a map if needed.
The returned values are only valid until the request object is released. Do not store references to returned values; make copies instead.
func (*Request) MaxRedirects ¶
MaxRedirects returns the maximum number of redirects configured for the Request.
func (*Request) Params ¶
Params returns an iterator over all query parameters in the Request. Use maps.Collect() to gather them into a map if needed.
The returned values are only valid until the request object is released. Do not store references to returned values; make copies instead.
func (*Request) PathParam ¶
PathParam returns the value of a named path parameter. If the parameter does not exist, an empty string is returned.
func (*Request) PathParams ¶
PathParams returns an iterator over all path parameters. Use maps.Collect() to gather them into a map if needed.
func (*Request) Reset ¶
func (r *Request) Reset()
Reset clears the Request object, returning it to its default state. Used by ReleaseRequest to recycle the object.
func (*Request) ResetPathParams ¶
ResetPathParams deletes all path parameters.
func (*Request) SetBoundary ¶
SetBoundary sets the multipart boundary.
func (*Request) SetContext ¶
SetContext sets the context for the Request, allowing request cancellation if ctx is done. See https://blog.golang.org/context article and the "context" package documentation.
func (*Request) SetCookies ¶
SetCookies sets multiple cookies at once, overriding previously set values.
func (*Request) SetCookiesWithStruct ¶
SetCookiesWithStruct sets multiple cookies from a struct, overriding previously set values.
func (*Request) SetFormData ¶
SetFormData sets a single form field and value, overriding any previously set value.
func (*Request) SetFormDataWithMap ¶
SetFormDataWithMap sets multiple form fields and values at once, overriding previously set values.
func (*Request) SetFormDataWithStruct ¶
SetFormDataWithStruct sets multiple form fields from a struct, overriding previously set values.
func (*Request) SetHeader ¶
SetHeader sets a single header field and value in the Request, overriding any previously set value.
func (*Request) SetHeaders ¶
SetHeaders sets multiple header fields and values at once, overriding previously set values.
func (*Request) SetMaxRedirects ¶
SetMaxRedirects sets the maximum number of redirects, overriding any previously set value.
func (*Request) SetMethod ¶
SetMethod sets the HTTP method for the Request. It is recommended to use the specialized methods (e.g., Get, Post) instead.
func (*Request) SetParam ¶
SetParam sets a single query parameter and value in the Request, overriding any previously set value.
func (*Request) SetParams ¶
SetParams sets multiple query parameters and their values at once, overriding previously set values.
func (*Request) SetParamsWithStruct ¶
SetParamsWithStruct sets multiple query parameters from a struct, overriding previously set values.
func (*Request) SetPathParam ¶
SetPathParam sets a single path parameter and value, overriding any previously set value.
func (*Request) SetPathParams ¶
SetPathParams sets multiple path parameters and values at once, overriding previously set values.
func (*Request) SetPathParamsWithStruct ¶
SetPathParamsWithStruct sets multiple path parameters from a struct, overriding previously set values.
func (*Request) SetRawBody ¶
SetRawBody sets the request body to raw bytes.
func (*Request) SetReferer ¶
SetReferer sets the Referer header, overriding any previously set value.
func (*Request) SetTimeout ¶
SetTimeout sets the timeout for the Request, overriding any previously set value.
func (*Request) SetUserAgent ¶
SetUserAgent sets the User-Agent header, overriding any previously set value.
type RequestHook ¶
RequestHook is a function invoked before the request is sent. It receives a Client and a Request, allowing you to modify the Request or Client data.
type Response ¶
Response represents the result of a request. It provides access to the response data.
func AcquireResponse ¶
func AcquireResponse() *Response
AcquireResponse returns a new (pooled) Response object. When done, release it with ReleaseResponse to reduce GC load.
func (*Response) Close ¶
func (r *Response) Close()
Close releases both the Request and Response objects back to their pools. After calling Close, do not use these objects.
func (*Response) Cookies ¶
Cookies returns all cookies set by the response.
The returned values are valid only until the response object is released. Do not store references to returned values; make copies instead.
func (*Response) Headers ¶
Headers returns all headers in the response using an iterator. Use maps.Collect() to gather them into a map if needed.
The returned values are valid only until the response object is released. Do not store references to returned values; make copies instead.
func (*Response) Reset ¶
func (r *Response) Reset()
Reset clears the Response object, making it ready for reuse.
func (*Response) Save ¶
Save writes the response body to a file or io.Writer. If a string path is provided, it creates directories if needed, then writes to a file. If an io.Writer is provided, it writes directly to it.
func (*Response) StatusCode ¶
StatusCode returns the HTTP status code of the executed request.
type ResponseHook ¶
ResponseHook is a function invoked after a response is received. It receives a Client, Response, and Request, allowing you to modify the Response data or perform actions based on the response.
type RetryConfig ¶
RetryConfig is an alias for the `retry.Config` type from the `addon/retry` package.
type SetFileFunc ¶
type SetFileFunc func(f *File)
SetFileFunc defines a function that modifies a File object.
func SetFileFieldName ¶
func SetFileFieldName(p string) SetFileFunc
SetFileFieldName sets the file's field name.
func SetFileReader ¶
func SetFileReader(r io.ReadCloser) SetFileFunc
SetFileReader sets the file's reader.
type WithStruct ¶
WithStruct is implemented by types that allow data to be stored from a struct via reflection.