urlutil

package
v0.0.0-...-fd57926 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package urlutil provides URL handling utilities for network operations

Index

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

func GetFileSize(rawURL string) (int64, error)

GetFileSize gets the size of a file from a URL without downloading it

func GetFilenameFromURL

func GetFilenameFromURL(rawURL string) (string, error)

GetFilenameFromURL extracts the filename from a URL

func GetRedirectURL

func GetRedirectURL(rawURL string) (string, error)

GetRedirectURL follows redirects and returns the final URL

func JoinURL

func JoinURL(baseURL string, paths ...string) (string, error)

JoinURL joins a base URL and path segments

func ValidateURL

func ValidateURL(rawURL string) error

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

Jump to

Keyboard shortcuts

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