requests
Explore the following sections to learn more:
requests
import "github.com/gemini-oss/rego/pkg/common/requests"
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 NewClient(options …any) *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, handler StreamHandler) 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)
)
func DecodeJSON
func DecodeJSON(body []byte, result any) error
* DecodeJSON
- @param body []byte
- @param result any
- @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 any) error
func SetJSONPayload
func SetJSONPayload(req *http.Request, data any) error
func SetQueryParams
func SetQueryParams(req *http.Request, query any)
func SetXMLPayload
func SetXMLPayload(req *http.Request, data any) error
type Client
* Client
- @param httpClient *http.Client
- @param headers Headers
type Client struct {
BodyType string
Cache *cache.Cache
Headers Headers
Log *log.Logger
RateLimiter *rl.RateLimiter
// contains filtered or unexported fields
}
func NewClient
func NewClient(options ...any) *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 any, data any) (*http.Response, []byte, error)
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 (c *Client) DownloadFile(url, directory, filename string, allowDuplicates bool) error
func (*Client) ExtractParam
func (c *Client) ExtractParam(u, parameter string) string
func (*Client) UpdateAcceptType
func (c *Client) UpdateAcceptType(contentType string)
UpdateHeaders changes the headers for the HTTP client
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
DownloadMetadata stores state for managing downloads.
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)
}
type Headers
type Headers map[string]string
type Paginator
* Paginator
- @param Self string
- @param NextPage string
- @param Paged bool
type Paginator struct {
Self string `json:"self"`
NextPageLink string `json:"next"`
NextPageToken string `json:"next_page_token"`
Paged bool `json:"paged"`
}
type RequestError
RequestError represents an API request error.
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"`
}
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
type StreamHandler func(decoder any) error
Generated by gomarkdoc