requests

package
v0.0.0-...-441cd5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

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

View Source
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

func DecodeJSON(body []byte, result interface{}) error

* DecodeJSON * @param body []byte * @param result interface{} * @return error

func IsNonRetryableCode

func IsNonRetryableCode(statusCode int) bool

IsNonRetryableCode checks if the provided response indicates a non-retryable error.

func IsPermanentRedirectCode

func IsPermanentRedirectCode(statusCode int) bool

IsPermanentRedirectCode checks if the provided HTTP status code is a permanent redirect code.

func IsRedirectCode

func IsRedirectCode(statusCode int) bool

IsRedirectCode checks if the provided HTTP status code is a redirect code.

func IsRetryableStatusCode

func IsRetryableStatusCode(statusCode int) bool

IsRetryableStatusCode checks if the provided HTTP status code is considered retryable.

func IsTemporaryErrorCode

func IsTemporaryErrorCode(statusCode int) bool

IsTemporaryErrorCode checks if an HTTP response indicates a temporary error.

func SetFormURLEncodedPayload

func SetFormURLEncodedPayload(req *http.Request, data interface{}) error

func SetJSONPayload

func SetJSONPayload(req *http.Request, data interface{}) error

func SetQueryParams

func SetQueryParams(req *http.Request, query interface{})

func SetXMLPayload

func SetXMLPayload(req *http.Request, data interface{}) error

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 (c *Client) CreateRequest(method string, url string) (*http.Request, error)

func (*Client) DoRequest

func (c *Client) DoRequest(ctx context.Context, method string, url string, query interface{}, data interface{}) (*http.Response, []byte, error)

func (*Client) DownloadFile

func (c *Client) DownloadFile(url, directory, filename string, allowDuplicates bool) error

func (*Client) ExtractParam

func (c *Client) ExtractParam(u, parameter string) string

func (*Client) UpdateBodyType

func (c *Client) UpdateBodyType(bodyType string)

UpdateHeaders changes the payload body for the HTTP client

func (*Client) UpdateContentType

func (c *Client) UpdateContentType(contentType string)

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 Headers

type Headers map[string]string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL