Documentation
¶
Index ¶
- Constants
- type DownloadRequest
- type DownloadResult
- type DownloadStatus
- type DownloadTask
- type EnqueueResult
- type Fetcher
- type FetcherOption
- func WithEnableOverwrite(eo bool) FetcherOption
- func WithHTTPClient(client *http.Client) FetcherOption
- func WithMaxWorkers(max int) FetcherOption
- func WithMonitor(m Monitor) FetcherOption
- func WithOnComplete(callback func(DownloadResult)) FetcherOption
- func WithOnError(callback func(DownloadRequest, error)) FetcherOption
- func WithTargetDir(dir string) FetcherOption
- type Monitor
- type MonitorSnapshot
- type TaskMonitor
- type TaskStatusCount
Constants ¶
const UnknownSize int64 = -1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DownloadRequest ¶
type DownloadResult ¶
func (*DownloadResult) IsAudio ¶
func (d *DownloadResult) IsAudio() bool
func (*DownloadResult) IsImage ¶
func (d *DownloadResult) IsImage() bool
func (*DownloadResult) IsVideo ¶
func (d *DownloadResult) IsVideo() bool
type DownloadStatus ¶
type DownloadStatus string
Download Monitoring
const ( StatusPending DownloadStatus = "pending" StatusInProgress DownloadStatus = "in_progress" StatusCompleted DownloadStatus = "completed" StatusFailed DownloadStatus = "failed" )
type DownloadTask ¶
type DownloadTask struct {
ID int `json:"id"`
FileName string `json:"fileName"`
FilePath string `json:"filePath"`
TotalBytes int64 `json:"totalBytes"`
DoneBytes int64 `json:"doneBytes"`
Status DownloadStatus `json:"status"`
Error string `json:"error,omitempty"`
StartedAt time.Time `json:"startedAt"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
DownloadSpeed float64 `json:"downloadSpeed"`
ETA string `json:"eta"`
QueuePosition int `json:"queuePosition"`
EnqueuedAt time.Time `json:"enqueuedAt"`
}
type EnqueueResult ¶ added in v1.2.0
type EnqueueResult struct {
Request DownloadRequest
Queued bool
Error error
}
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher is responsible for managing download requests and processing them. It supports configuration through functional options.
func New ¶
func New(options ...FetcherOption) *Fetcher
New creates a new Fetcher instance with the provided options.
func (*Fetcher) Enqueue ¶
func (f *Fetcher) Enqueue(req DownloadRequest) EnqueueResult
Enqueue adds a download request to the Fetcher's queue.
func (*Fetcher) EnqueueMany ¶
func (f *Fetcher) EnqueueMany(reqs []DownloadRequest) []EnqueueResult
EnqueueMany adds multiple download requests to the Fetcher's queue.
type FetcherOption ¶
type FetcherOption func(*Fetcher)
FetcherOption defines a function type for configuring the Fetcher. Each option function modifies the Fetcher's fields.
func WithEnableOverwrite ¶ added in v1.3.0
func WithEnableOverwrite(eo bool) FetcherOption
WithEnableOverwrite sets the enableOverwrite for the Fetcher When enabled the files gets overwritten if they exists
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) FetcherOption
WithHTTPClient sets a custom HTTP client for the Fetcher.
func WithMaxWorkers ¶
func WithMaxWorkers(max int) FetcherOption
WithMaxWorkers sets the maximum number of concurrent workers for the Fetcher.
func WithMonitor ¶
func WithMonitor(m Monitor) FetcherOption
WithMonitor sets the Monitor for the Fetcher.
func WithOnComplete ¶
func WithOnComplete(callback func(DownloadResult)) FetcherOption
WithOnComplete sets the callback function to be called on download completion.
func WithOnError ¶
func WithOnError(callback func(DownloadRequest, error)) FetcherOption
WithOnError sets the callback function to be called on download error.
func WithTargetDir ¶
func WithTargetDir(dir string) FetcherOption
WithTargetDir sets the target directory for downloaded files.
type Monitor ¶
type Monitor interface {
GetSnapshot() MonitorSnapshot
EventSignal() <-chan struct{}
// contains filtered or unexported methods
}
type MonitorSnapshot ¶
type MonitorSnapshot struct {
Tasks []DownloadTask `json:"tasks"`
Count TaskStatusCount `json:"count"`
}
type TaskMonitor ¶
type TaskMonitor struct {
// contains filtered or unexported fields
}
func (*TaskMonitor) EventSignal ¶ added in v1.1.0
func (m *TaskMonitor) EventSignal() <-chan struct{}
EventSignal returns a read-only channel that signals whenever the TaskMonitor's state changes.
func (*TaskMonitor) GetSnapshot ¶
func (m *TaskMonitor) GetSnapshot() MonitorSnapshot
GetSnapshot returns a copy of the current state of all download