fetch package - github.com/go-zoox/fetch - Go Packages (original) (raw)

DELETE is request method DELETE

EnvDEBUG is the DEBUG env name

GET is request method GET

HEAD is request method HEAD

PATCH is request method PATCH

POST is request method POST

PUT is request method PUT

BaseURL is the default base url

ErrCannotCopyFile is the error when the file cannot be copied

ErrCannotCreateFormFile is the error when the form file cannot be created

ErrCannotCreateRequest is the error when the request cannot be created

ErrCannotSendBodyWithGet is the error when the body cannot be sent with GET method

ErrCookieEmptyKey is the error when the key is empty

ErrInvalidBodyMultipart is the error when the body is invalid for multipart

ErrInvalidContentType is the error when the content type is invalid

ErrInvalidJSONBody is the error when the body is not a valid JSON

ErrInvalidMethod is the error when the method is invalid

ErrInvalidURLFormEncodedBody is the error when the body is invalid for url form encoded

ErrReadingResponse is the error when the response cannot be read

ErrSendingRequest is the error when the request cannot be sent

ErrTooManyArguments is the error when the number of arguments is too many

ErrorInvalidBody is the error when the body is invalid

METHODS is the list of supported methods

Timeout is the default timeout

UserAgent is the default user agent

Version is the version of this package

func DefaultUserAgent() string

DefaultUserAgent returns the default user agent

SetBaseURL sets the base url

SetTimeout sets the timeout

func SetUserAgent(userAgent string)

SetUserAgent sets the user agent

BasicAuth is the basic auth

type Body added in v1.4.3

Body is the body of the request

Config is the configuration for the fetch

func DefaultConfig() *Config

DefaultConfig returns the default config

func (c *Config) Clone() *Config

Clone returns a clone of the config

func (c *Config) Merge(config *Config)

Merge merges the config with the given config

DataSource defines the interface for loading data from a data source.

type Fetch struct { Errors []error

}

Fetch is the Fetch Client

Create creates a new fetch with base url Specially useful for Client SDK

func New(cfg ...*Config) *Fetch

New creates a fetch client

Session is remembered between requests

func (f *Fetch) Clone() *Fetch

Clone creates a new fetch

Config returns the config of fetch

func (f Fetch) Delete(url string, config ...Config) *Fetch

Delete is http.delete

Download downloads file by url

Execute executes the request

func (f Fetch) Get(url string, config ...Config) *Fetch

Get is http.get

func (f Fetch) Head(url string, config ...Config) *Fetch

Head is http.head

func (f Fetch) Patch(url string, config ...Config) *Fetch

Patch is http.patch

func (f Fetch) Post(url string, config ...Config) *Fetch

Post is http.post

func (f Fetch) Put(url string, config ...Config) *Fetch

Put is http.put

func (f *Fetch) Retry(before func(f Fetch)) (Response, error)

Retry retries the request

func (f *Fetch) SetAccept(accept string) *Fetch

SetAccept sets the accept header

func (f *Fetch) SetAcceptEncoding(acceptEncoding string) *Fetch

SetAcceptEncoding sets the accept encoding

func (f *Fetch) SetAcceptLanguage(acceptLanguage string) *Fetch

SetAcceptLanguage sets the accept language

func (f *Fetch) SetAuthorization(token string) *Fetch

SetAuthorization sets the authorization token

func (f *Fetch) SetBaseURL(url string) *Fetch

SetBaseURL sets the base url

func (f *Fetch) SetBasicAuth(username, password string) *Fetch

SetBasicAuth sets the basic auth username and password

func (f *Fetch) SetBearToken(token string) *Fetch

SetBearToken sets the bear token

func (*Fetch) SetBody

func (f *Fetch) SetBody(body Body) *Fetch

SetBody sets the body

func (f *Fetch) SetCacheControl(cacheControl string) *Fetch

SetCacheControl sets the cache control

func (f Fetch) SetConfig(configs ...Config) *Fetch

SetConfig sets the config of fetch

func (*Fetch) SetContentType added in v1.4.0

func (f *Fetch) SetContentType(contentType string) *Fetch

SetContentType ...

SetContext sets the context

func (f *Fetch) SetCookie(key, value string) *Fetch

SetCookie sets the cookie

func (f *Fetch) SetDownloadFilePath(filepath string) *Fetch

SetDownloadFilePath sets the download file path

func (f *Fetch) SetHeader(key, value string) *Fetch

SetHeader sets the header key and value

func (f *Fetch) SetMethod(method string) *Fetch

SetMethod sets the method

func (f *Fetch) SetParam(key, value string) *Fetch

SetParam sets the param key and value

func (f *Fetch) SetProgressCallback(callback func(percent int64, current, total int64)) *Fetch

SetProgressCallback sets the progress callback

func (f *Fetch) SetProxy(proxy string) *Fetch

SetProxy sets the proxy

support http, https, socks5

example: http://127.0.0.1:17890 https://127.0.0.1:17890 socks5://127.0.0.1:17890

func (f *Fetch) SetQuery(key, value string) *Fetch

SetQuery sets the query key and value

func (f *Fetch) SetReferrer(referrer string) *Fetch

SetReferrer sets the referrer

SetTimeout sets the timeout

SetURL sets the url of fetch

func (f *Fetch) SetUserAgent(userAgent string) *Fetch

SetUserAgent sets the user agent

func (f Fetch) Stream(url string, config ...Config) *Fetch

Stream ...

Headers is the headers of the request

Get returns the value of the given key

Set sets the value of the given key

NamedReadCloser is a named reader

CreateNamedReader creates a named reader

multipart.File, that is Request.ParseMultipartForm, does not have a name
so we need to create a named reader to get the file name

when uploading a file with multipart/form-data

type OnProgress func(percent int64, current, total int64)

OnProgress is the progress callback

MarshalJSON returns the json string

UnmarshalJSON unmarshals the json string

Params is the params of the request

Get returns the value of the given key

Set sets the value of the given key

type Progress struct { Reporter func(percent int64, current, total int64) Total int64 Current int64 }

Progress is a progress event

Write writes the data to the progress event

Query is the query of the request

Get returns the value of the given key

Set sets the value of the given key

Response is the fetch response

Delete is a wrapper for the Delete method of the Client

Download is a wrapper for the Download method of the Client

Get is a wrapper for the Get method of the Client

Head is a wrapper for the Head method of the Client

Patch is a wrapper for the Patch method of the Client

Post is a wrapper for the Post method of the Client

Put is a wrapper for the Put method of the Client

Stream is a wrapper for the Stream method of the Client

Upload is a wrapper for the Upload method of the Client

AcceptRanges returns x-accept-ranges of the response

func (*Response) ContentEncoding added in v1.4.4

func (r *Response) ContentEncoding() string

ContentEncoding returns content encoding of the response

func (*Response) ContentLanguage added in v1.4.4

func (r *Response) ContentLanguage() string

ContentLanguage returns content language of the response

func (*Response) ContentLength added in v1.4.4

func (r *Response) ContentLength() int

ContentLength returns content length of the response

func (*Response) ContentType added in v1.4.4

ContentType returns content type of the response

Error returns error with status and response string.

Get returns the value of the key

JSON returns the body as json string

Location returns location of the response

Ok returns true if status code is 2xx

SetCookie returns set-cookie of the response

func (r *Response) StatusCode() int

StatusCode returns status code of the response

StatusText returns status text of the response

String returns the body as string

func (r *Response) TransferEncoding() string

TransferEncoding returns transfer encoding of the response

func (r *Response) UnmarshalJSON(v interface{}) error

UnmarshalJSON unmarshals body to json struct

@TODO bug when lint (go vet) method UnmarshalJSON(v interface{}) error should have signature UnmarshalJSON([]byte) error

func (r *Response) UnmarshalYAML(v interface{}) error

UnmarshalYAML unmarshals body to yaml struct

Value returns the body as gjson.Result

XPoweredBy returns x-powered-by of the response

XRequestID returns x-request-id of the response