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 any) 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 any) error
- func SetJSONPayload(req *http.Request, data any) error
- func SetQueryParams(req *http.Request, query any)
- func SetXMLPayload(req *http.Request, data any) 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 any, data any) (*http.Response, []byte, error)
- func (c *Client) DoStream(ctx context.Context, method string, url string, query any, data any, ...) error
- func (c *Client) DownloadFile(url, directory, filename string, allowDuplicates bool) error
- func (c *Client) ExtractParam(u, parameter string) string
- func (c *Client) UpdateAcceptType(contentType string)
- func (c *Client) UpdateBodyType(bodyType string)
- func (c *Client) UpdateContentType(contentType string)
- type DownloadMetadata
- type Headers
- type Paginator
- type RequestError
- type StreamHandler
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 any * @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 SetQueryParams ¶
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 (*Client) CreateRequest ¶
func (*Client) DoStream ¶
func (c *Client) DoStream(ctx context.Context, method string, url string, query any, data any, handler StreamHandler) error
DoStream performs an HTTP request optimized for streaming responses. It automatically creates an appropriate decoder (XML or JSON) based on the content type and passes it to the handler function for processing the stream.
func (*Client) DownloadFile ¶
func (*Client) ExtractParam ¶
func (*Client) UpdateAcceptType ¶
UpdateHeaders changes the headers for the HTTP client
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.
type StreamHandler ¶
StreamHandler is a callback function for processing streaming data with a decoder