fafnir

package module
v0.0.0-...-22ca295 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: GPL-3.0 Imports: 11 Imported by: 1

README

Fafnir


Fafnir is an library that act as an download manager with advanced features for your App

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyQueue    = fmt.Errorf("Queue is empty")
	ErrQueueNotFound = fmt.Errorf("Queue doesn't exist")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// ErrCh!=nil means errors during download are sent to
	// this channel for the client to consume.
	ErrChan                chan error
	MaxConcurrentDownloads uint
	// MaxFailError is the maximum number that an entry can fail
	// after failing N times it will not make it will not be re-queued
	MaxFailError uint
	// UpdateTimeMs specify the rate of which the info about the
	// entity that is currently downloading should be updated ,
	// this should be in millisecond (ms)
	UpdateTimeMs uint
	Repo         Repository
	// WaitGroup!=nil will update the wait group as goroutines
	// are started and finished.
	WaitGroup *sync.WaitGroup
}

type Entry

type Entry struct {
	ID          int
	Filename    string
	DwnDir      string
	Url         string
	Description string
	ExtraData   EntryExtraData
}

type EntryExtraData

type EntryExtraData struct {
	FailCount       int
	Size            int64
	BytesTransfered int64
	BytesPerSecond  float64
	ETA             time.Time
	Err             error
	Duration        time.Duration
	CanResume       bool
	DidResume       bool
	Start           time.Time
	End             time.Time
	Progress        float64
}

type EntryRepository

type EntryRepository interface {
	Update(Entry) error
	Add(string, string, string, string, string) error
	Complete(Entry) error
}

type Fafnir

type Fafnir struct {
	Cfg *Config
}

func New

func New(cfg *Config) (*Fafnir, error)

func (*Fafnir) Add

func (f *Fafnir) Add(queueName, link, dwnDir, filename, description string) error

func (*Fafnir) SortByName

func (f *Fafnir) SortByName(queueName string, descending bool) error

func (*Fafnir) StartQueueDownload

func (f *Fafnir) StartQueueDownload(queueName string) error

func (*Fafnir) StartQueueDownloadWithCtx

func (f *Fafnir) StartQueueDownloadWithCtx(ctx context.Context, queueName string) error

type Queue

type Queue struct {
	Name          string
	Entries       []Entry
	FailedEntries []Entry
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(name string) *Queue

func (*Queue) DeQueue

func (q *Queue) DeQueue() (Entry, error)

func (*Queue) DeQueueFail

func (q *Queue) DeQueueFail() (Entry, error)

func (*Queue) EnQueue

func (q *Queue) EnQueue(e Entry) error

func (*Queue) EnQueueFail

func (q *Queue) EnQueueFail(e Entry) error

func (*Queue) SortByName

func (q *Queue) SortByName(descending bool)

type QueueRepository

type QueueRepository interface {
	Fetch() ([]*Queue, error)
	Create(string) error
	Delete(string) error
	Get(string, chan error) (*Queue, error)
}

type Repository

type Repository interface {
	QueueRepository
	EntryRepository
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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