Documentation
¶
Overview ¶
Package urlutil provides URL handling utilities for network operations
Index ¶
- Constants
- func DownloadFile(sourceURL string, options DownloadOptions) (string, error)
- func GetFileSize(rawURL string) (int64, error)
- func GetFilenameFromURL(rawURL string) (string, error)
- func GetRedirectURL(rawURL string) (string, error)
- func JoinURL(baseURL string, paths ...string) (string, error)
- func ValidateURL(rawURL string) error
- type DownloadOptions
Constants ¶
View Source
const ( DefaultTimeout = 30 // 30 seconds DefaultMaxRetries = 3 // 3 retry attempts DefaultRetryDelay = 2 // 2 seconds between retries )
Default values for download options
Variables ¶
This section is empty.
Functions ¶
func DownloadFile ¶
func DownloadFile(sourceURL string, options DownloadOptions) (string, error)
DownloadFile downloads a file from a URL with the specified options
func GetFileSize ¶
GetFileSize gets the size of a file from a URL without downloading it
func GetFilenameFromURL ¶
GetFilenameFromURL extracts the filename from a URL
func GetRedirectURL ¶
GetRedirectURL follows redirects and returns the final URL
func ValidateURL ¶
ValidateURL checks if a URL is valid and reachable
Types ¶
type DownloadOptions ¶
type DownloadOptions struct {
// Output file path (if empty, will use the filename from URL)
OutputPath string
// HTTP timeout in seconds (default: 30s)
Timeout int
// Expected file checksum for verification
ExpectedChecksum string
// Checksum algorithm (md5, sha1, sha256)
ChecksumAlgorithm string
// Skip TLS verification
SkipTLSVerify bool
// HTTP headers to send with the request
Headers map[string]string
// Auto-retry settings
MaxRetries int
RetryDelay int // in seconds
// Progress callback (receives bytes downloaded and total size)
ProgressCallback func(bytesDownloaded, totalBytes int64)
}
DownloadOptions represents options for downloading files
func DefaultDownloadOptions ¶
func DefaultDownloadOptions() DownloadOptions
DefaultDownloadOptions returns a DownloadOptions with sensible defaults
Click to show internal directories.
Click to hide internal directories.