Documentation
¶
Index ¶
- Variables
- func DefaultUserAgent() string
- func SetBaseURL(url string)
- func SetTimeout(timeout time.Duration)
- func SetUserAgent(userAgent string)
- type Config
- type ConfigBody
- type ConfigHeaders
- type ConfigParams
- type ConfigQuery
- type DataSource
- type Fetch
- func (f *Fetch) Clone() *Fetch
- func (f *Fetch) Config() (*Config, error)
- func (f *Fetch) Delete(url string, config ...*Config) *Fetch
- func (f *Fetch) Download(url string, filepath string, config ...*Config) *Fetch
- func (f *Fetch) Execute() (*Response, error)
- func (f *Fetch) Get(url string, config ...*Config) *Fetch
- func (f *Fetch) Head(url string, config ...*Config) *Fetch
- func (f *Fetch) Patch(url string, config ...*Config) *Fetch
- func (f *Fetch) Post(url string, config ...*Config) *Fetch
- func (f *Fetch) Put(url string, config ...*Config) *Fetch
- func (f *Fetch) Send() (*Response, error)
- func (f *Fetch) SetAuthorization(token string) *Fetch
- func (f *Fetch) SetBaseURL(url string) *Fetch
- func (f *Fetch) SetBasicAuth(username, password string) *Fetch
- func (f *Fetch) SetBearToken(token string) *Fetch
- func (f *Fetch) SetBody(body ConfigBody) *Fetch
- func (f *Fetch) SetConfig(configs ...*Config) *Fetch
- func (f *Fetch) SetDownloadFilePath(filepath string) *Fetch
- func (f *Fetch) SetHeader(key, value string) *Fetch
- func (f *Fetch) SetMethod(method string) *Fetch
- func (f *Fetch) SetParam(key, value string) *Fetch
- func (f *Fetch) SetProxy(proxy string) *Fetch
- func (f *Fetch) SetQuery(key, value string) *Fetch
- func (f *Fetch) SetTimeout(timeout time.Duration) *Fetch
- func (f *Fetch) SetURL(url string) *Fetch
- func (f *Fetch) SetUserAgent(userAgent string) *Fetch
- type Response
- func Delete(url string, config *Config) (*Response, error)
- func Download(url string, filepath string, config ...interface{}) (*Response, error)
- func Get(url string, config ...interface{}) (*Response, error)
- func Head(url string, config ...interface{}) (*Response, error)
- func Patch(url string, config *Config) (*Response, error)
- func Post(url string, config *Config) (*Response, error)
- func Put(url string, config *Config) (*Response, error)
Constants ¶
This section is empty.
Variables ¶
var BaseURL = ""
BaseURL is the default base url
var DELETE = "DELETE"
DELETE is request method DELETE
var ErrCannotCopyFile = errors.New("cannot copy file")
ErrCannotCopyFile is the error when the file cannot be copied
var ErrCannotCreateFormFile = errors.New("cannot create form file")
ErrCannotCreateFormFile is the error when the form file cannot be created
var ErrCannotCreateRequest = errors.New("cannot create request")
ErrCannotCreateRequest is the error when the request cannot be created
var ErrCannotSendBodyWithGet = errors.New("cannot send body with GET method")
ErrCannotSendBodyWithGet is the error when the body cannot be sent with GET method
var ErrInvalidBodyMultipart = errors.New("invalid body multipart")
ErrInvalidBodyMultipart is the error when the body is invalid for multipart
var ErrInvalidContentType = errors.New("invalid content type")
ErrInvalidContentType is the error when the content type is invalid
var ErrInvalidJSONBody = errors.New("error marshalling body")
ErrInvalidJSONBody is the error when the body is not a valid JSON
var ErrInvalidMethod = errors.New("invalid method")
ErrInvalidMethod is the error when the method is invalid
var ErrInvalidURLFormEncodedBody = errors.New("invalid url form encoded body")
ErrInvalidURLFormEncodedBody is the error when the body is invalid for url form encoded
var ErrReadingResponse = errors.New("error reading response")
ErrReadingResponse is the error when the response cannot be read
var ErrSendingRequest = errors.New("error sending request")
ErrSendingRequest is the error when the request cannot be sent
var ErrTooManyArguments = errors.New("too many arguments")
ErrTooManyArguments is the error when the number of arguments is too many
var ErrorInvalidBody = errors.New("invalid body")
ErrorInvalidBody is the error when the body is invalid
var GET = "GET"
GET is request method GET
var HEAD = "HEAD"
HEAD is request method HEAD
METHODS is the list of supported methods
var PATCH = "PATCH"
PATCH is request method PATCH
var POST = "POST"
POST is request method POST
var PUT = "PUT"
PUT is request method PUT
var Timeout = 60 * time.Second
Timeout is the default timeout
var UserAgent = fmt.Sprintf("GoFetch/%s (github.com/go-zoox/fetch)", Version)
UserAgent is the default user agent
var Version = "1.3.2"
Version is the version of this package
Functions ¶
func DefaultUserAgent ¶
func DefaultUserAgent() string
DefaultUserAgent returns the default user agent
Types ¶
type Config ¶
type Config struct { URL string Method string Headers ConfigHeaders Query ConfigQuery Params ConfigParams Body ConfigBody // BaseURL string Timeout time.Duration // DownloadFilePath string // Proxy string }
Config is the configuration for the fetch
type ConfigHeaders ¶
ConfigHeaders is the headers of the request
func (ConfigHeaders) Get ¶
func (h ConfigHeaders) Get(key string) string
Get returns the value of the given key
type ConfigParams ¶
ConfigParams is the params of the request
func (ConfigParams) Get ¶
func (h ConfigParams) Get(key string) string
Get returns the value of the given key
type ConfigQuery ¶
ConfigQuery is the query of the request
func (ConfigQuery) Get ¶
func (h ConfigQuery) Get(key string) string
Get returns the value of the given key
type DataSource ¶ added in v1.1.0
DataSource defines the interface for loading data from a data source.
type Fetch ¶
type Fetch struct { Errors []error // contains filtered or unexported fields }
Fetch is the Fetch Client
func (*Fetch) SetAuthorization ¶ added in v1.1.1
SetAuthorization sets the authorization token
func (*Fetch) SetBaseURL ¶
SetBaseURL sets the base url
func (*Fetch) SetBasicAuth ¶ added in v1.1.1
SetBasicAuth sets the basic auth username and password
func (*Fetch) SetBearToken ¶ added in v1.1.1
SetBearToken sets the bear token
func (*Fetch) SetDownloadFilePath ¶ added in v1.1.8
SetDownloadFilePath sets the download file path
func (*Fetch) SetProxy ¶ added in v1.2.0
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 (*Fetch) SetTimeout ¶
SetTimeout sets the timeout
func (*Fetch) SetUserAgent ¶
SetUserAgent sets the user agent
type Response ¶
type Response struct { Status int Headers http.Header Body []byte // Request *Config // contains filtered or unexported fields }
Response is the fetch response
func (*Response) UnmarshalJSON ¶ added in v1.1.4
UnmarshalJSON unmarshals body to json struct
@TODO bug when lint (go vet) method UnmarshalJSON(v interface{}) error should have signature UnmarshalJSON([]byte) error
func (*Response) UnmarshalYAML ¶ added in v1.1.4
UnmarshalYAML unmarshals body to yaml struct