Documentation
¶
Overview ¶
Package cache manages downloaded files and their metadata.
Index ¶
- Constants
- Variables
- func CalculateChecksum(filePath string) (string, error)
- type DownloadOptions
- type DownloadResult
- type Entry
- type EntryMetadata
- type Manager
- func (m *Manager) Download(ctx context.Context, opts DownloadOptions, authToken string, ...) (*DownloadResult, error)
- func (m *Manager) EntryPath(licenseKey string, downloadID, version string) (string, error)
- func (m *Manager) GetEntry(licenseKey string, downloadID, version string) (*Entry, error)
- func (m *Manager) List() ([]*Entry, error)
- func (m *Manager) ListForLicense(licenseKey string) ([]*Entry, error)
- func (m *Manager) PurgeAll() error
- func (m *Manager) PurgeLicense(licenseKey string) error
- func (m *Manager) SaveMetadata(licenseKey string, metadata *EntryMetadata) error
- func (m *Manager) Verify(entry *Entry) (bool, error)
- type ProgressCallback
Constants ¶
const MetadataFilename = ".metadata.json"
MetadataFilename is the name of the metadata file for each cache entry.
Variables ¶
var ( // ErrCacheMiss is returned when a requested cache entry does not exist. ErrCacheMiss = errors.New("cache miss") // ErrChecksumMismatch indicates a checksum verification failure. ErrChecksumMismatch = errors.New("checksum mismatch") // ErrInvalidInput indicates invalid input to a cache operation. ErrInvalidInput = errors.New("invalid input") // ErrAuthExpired indicates the authentication token has expired. ErrAuthExpired = errors.New("authentication expired") // ErrDownloadFailed indicates a download operation failed. ErrDownloadFailed = errors.New("download failed") )
Functions ¶
func CalculateChecksum ¶
CalculateChecksum computes a file's SHA-256 checksum.
Types ¶
type DownloadOptions ¶
type DownloadOptions struct {
LicenseKey string
DownloadID string // e.g., "xenforo", "xfmg"
Version string
URL string
ExpectedChecksum string // SHA-256, optional
ExpectedSize int64 // 0 = unknown
Filename string // overrides Content-Disposition
SkipCacheCheck bool
}
DownloadOptions specifies download parameters.
type DownloadResult ¶
DownloadResult contains information about a completed download.
type Entry ¶
type Entry struct {
LicenseKey string
Metadata EntryMetadata
FilePath string
}
Entry represents a cached download file.
type EntryMetadata ¶
type EntryMetadata struct {
DownloadID string `json:"download_id"`
Version string `json:"version"`
Filename string `json:"filename"`
Checksum string `json:"checksum"`
Size int64 `json:"size"`
DownloadedAt time.Time `json:"downloaded_at"`
SourceURL string `json:"source_url,omitempty"`
}
EntryMetadata holds information about a cached file.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages cache storage on disk.
func (*Manager) Download ¶
func (m *Manager) Download(ctx context.Context, opts DownloadOptions, authToken string, progress ProgressCallback) (*DownloadResult, error)
Download downloads and caches a file, optionally using an authentication token.
func (*Manager) ListForLicense ¶
ListForLicense returns all cached entries for a specific license.
func (*Manager) PurgeLicense ¶
PurgeLicense removes all cached files for a specific license.
func (*Manager) SaveMetadata ¶
func (m *Manager) SaveMetadata(licenseKey string, metadata *EntryMetadata) error
SaveMetadata saves cache entry metadata to disk.
type ProgressCallback ¶
type ProgressCallback func(current, total int64)
ProgressCallback reports download progress; total is -1 if unknown.