Documentation
¶
Overview ¶
pkg/common/requests/download.go
pkg/common/requests/error_handling.go
pkg/common/requests/progress.go
pkg/common/requests/requests.go
pkg/common/requests/status_codes.go
Index ¶
- Constants
- func DecodeJSON(body []byte, result interface{}) error
- func IsNonRetryableCode(statusCode int) bool
- func IsPermanentRedirectCode(statusCode int) bool
- func IsRedirectCode(statusCode int) bool
- func IsRetryableStatusCode(statusCode int) bool
- func IsTemporaryErrorCode(statusCode int) bool
- func SetFormURLEncodedPayload(req *http.Request, data interface{}) error
- func SetJSONPayload(req *http.Request, data interface{}) error
- func SetQueryParams(req *http.Request, query interface{})
- func SetXMLPayload(req *http.Request, data interface{}) error
- type Client
- func (c *Client) CreateRequest(method string, url string) (*http.Request, error)
- func (c *Client) DoRequest(ctx context.Context, method string, url string, query interface{}, ...) (*http.Response, []byte, error)
- func (c *Client) DownloadFile(url, directory, filename string, allowDuplicates bool) error
- func (c *Client) ExtractParam(u, parameter string) string
- func (c *Client) UpdateBodyType(bodyType string)
- func (c *Client) UpdateContentType(contentType string)
- type DownloadMetadata
- type Headers
- type Paginator
- type RequestError
Constants ¶
const ( All = "*/*" // RFC-7231 (https://www.rfc-editor.org/rfc/rfc7231.html) Atom = "application/atom+xml" // RFC-4287 (https://www.rfc-editor.org/rfc/rfc4287.html) CSS = "text/css" // RFC-2318 (https://www.rfc-editor.org/rfc/rfc2318.html) Excel = "application/vnd.ms-excel" // Proprietary FormURLEncoded = "application/x-www-form-urlencoded" // RFC-1866 (https://www.rfc-editor.org/rfc/rfc1866.html) GIF = "image/gif" // RFC-2046 (https://www.rfc-editor.org/rfc/rfc2046.html) HTML = "text/html" // RFC-2854 (https://www.rfc-editor.org/rfc/rfc2854.html) JPEG = "image/jpeg" // RFC-2045 (https://www.rfc-editor.org/rfc/rfc2045.html) JavaScript = "text/javascript" // RFC-9239 (https://www.rfc-editor.org/rfc/rfc9239.html) JSON = "application/json" // RFC-8259 (https://www.rfc-editor.org/rfc/rfc8259.html) MP3 = "audio/mpeg" // RFC-3003 (https://www.rfc-editor.org/rfc/rfc3003.html) MP4 = "video/mp4" // RFC-4337 (https://www.rfc-editor.org/rfc/rfc4337.html) MPEG = "video/mpeg" // RFC-4337 (https://www.rfc-editor.org/rfc/rfc4337.html) MultipartFormData = "multipart/form-data" // RFC-7578 (https://www.rfc-editor.org/rfc/rfc7578.html) OctetStream = "application/octet-stream" // RFC-2046 (https://www.rfc-editor.org/rfc/rfc2046.html) PDF = "application/pdf" // RFC-3778 (https://www.rfc-editor.org/rfc/rfc3778.html) PNG = "image/png" // RFC-2083 (https://www.rfc-editor.org/rfc/rfc2083.html) Plain = "text/plain" // RFC-2046 (https://www.rfc-editor.org/rfc/rfc2046.html) RSS = "application/rss+xml" // RFC-7303 (https://www.rfc-editor.org/rfc/rfc4287.html) WAV = "audio/wav" // RFC-2361 (https://www.rfc-editor.org/rfc/rfc2361.html) XML = "application/xml" // RFC-7303 (https://www.rfc-editor.org/rfc/rfc7303.html) YAML = "application/yaml" // RFC-9512 (https://www.rfc-editor.org/rfc/rfc9512.html) ZIP = "application/zip" // RFC-1951 (https://www.rfc-editor.org/rfc/rfc1951.html) )
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
* DecodeJSON * @param body []byte * @param result interface{} * @return error
func IsNonRetryableCode ¶
IsNonRetryableCode checks if the provided response indicates a non-retryable error.
func IsPermanentRedirectCode ¶
IsPermanentRedirectCode checks if the provided HTTP status code is a permanent redirect code.
func IsRedirectCode ¶
IsRedirectCode checks if the provided HTTP status code is a redirect code.
func IsRetryableStatusCode ¶
IsRetryableStatusCode checks if the provided HTTP status code is considered retryable.
func IsTemporaryErrorCode ¶
IsTemporaryErrorCode checks if an HTTP response indicates a temporary error.
func SetJSONPayload ¶
func SetQueryParams ¶
func SetXMLPayload ¶
Types ¶
type Client ¶
type Client struct { BodyType string Cache *cache.Cache Headers Headers Log *log.Logger RateLimiter *rl.RateLimiter // contains filtered or unexported fields }
* Client * @param httpClient *http.Client * @param headers Headers
func NewClient ¶
func NewClient(options ...interface{}) *Client
* NewClient * @param headers Headers * @return *Client
func (*Client) CreateRequest ¶
func (*Client) DownloadFile ¶
func (*Client) ExtractParam ¶
func (*Client) UpdateBodyType ¶
UpdateHeaders changes the payload body for the HTTP client
func (*Client) UpdateContentType ¶
UpdateHeaders changes the headers for the HTTP client
type DownloadMetadata ¶
type DownloadMetadata struct { URL string // Source URL FilePath string // Full path to the downloaded file FileName string // Name of the file BytesReceived int64 // Bytes downloaded so far TotalSize int64 // Total size of the file LastModified time.Time // Last modified time from server Checksum string // For checksum validation (optional) }
DownloadMetadata stores state for managing downloads.
type Paginator ¶
type Paginator struct { Self string `json:"self"` NextPageLink string `json:"next"` NextPageToken string `json:"next_page_token"` Paged bool `json:"paged"` }
* Paginator * @param Self string * @param NextPage string * @param Paged bool
type RequestError ¶
type RequestError struct { StatusCode int `json:"status_code"` Method string `json:"method"` URL string `json:"url"` Message string `json:"message"` RawResponse string `json:"raw_response"` }
RequestError represents an API request error.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
Error returns a string representation of the RequestError.