subscription

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const CatalogSchema = "mihari.subscriptions/v1"

Variables

This section is empty.

Functions

func Due

func Due(catalog Catalog, now time.Time) []string

func Generate

func Generate(base Document, overrides map[string]any, settings config.Settings) ([]byte, error)

func RetryDelay

func RetryDelay(failures int, minimum, maximum time.Duration) time.Duration

func Save

func Save(path string, catalog Catalog) error

Types

type Catalog

type Catalog struct {
	Schema         string    `yaml:"schema"`
	GlobalInterval string    `yaml:"global-interval"`
	ActiveID       string    `yaml:"active-id,omitempty"`
	Profiles       []Profile `yaml:"profiles,omitempty"`
}

func Defaults

func Defaults() Catalog

func Load

func Load(path string) (Catalog, error)

func LoadOrCreate

func LoadOrCreate(path string) (Catalog, error)

func (Catalog) Clone

func (c Catalog) Clone() Catalog

func (Catalog) EffectiveInterval

func (c Catalog) EffectiveInterval(profile Profile) time.Duration

func (Catalog) Index

func (c Catalog) Index(id string) int

func (*Catalog) Normalize

func (c *Catalog) Normalize() error

func (Catalog) Public

func (c Catalog) Public() PublicCatalog

type Document

type Document map[string]any

func ParseDocument

func ParseDocument(content []byte) (Document, error)

type Downloader

type Downloader struct {
	Client   *http.Client
	MaxBytes int64
}

func NewDownloader

func NewDownloader(client *http.Client) *Downloader

func (*Downloader) Fetch

func (d *Downloader) Fetch(ctx context.Context, input FetchRequest) (FetchResult, error)

type FetchRequest

type FetchRequest struct {
	URL          string
	ETag         string
	LastModified string
}

type FetchResult

type FetchResult struct {
	Content      []byte
	ETag         string
	LastModified string
	// Userinfo is the raw subscription-userinfo response header when present.
	Userinfo    string
	NotModified bool
}

type Fetcher

type Fetcher interface {
	Fetch(context.Context, FetchRequest) (FetchResult, error)
}

type PreparedRefresh

type PreparedRefresh struct {
	// contains filtered or unexported fields
}

func (PreparedRefresh) Document

func (p PreparedRefresh) Document() Document

func (PreparedRefresh) ProfileID

func (p PreparedRefresh) ProfileID() string

type Profile

type Profile struct {
	ID           string    `yaml:"id"`
	Name         string    `yaml:"name"`
	URL          string    `yaml:"url"`
	Enabled      bool      `yaml:"enabled"`
	AutoRefresh  bool      `yaml:"auto-refresh"`
	Interval     string    `yaml:"interval,omitempty"`
	Version      uint64    `yaml:"version,omitempty"`
	Generation   uint64    `yaml:"generation,omitempty"`
	UpdatedAt    time.Time `yaml:"updated-at,omitempty"`
	ETag         string    `yaml:"etag,omitempty"`
	LastModified string    `yaml:"last-modified,omitempty"`
	LastError    string    `yaml:"last-error,omitempty"`
	// Traffic quota from subscription-userinfo (bytes). Zero means unknown.
	Upload   int64 `yaml:"upload,omitempty"`
	Download int64 `yaml:"download,omitempty"`
	Total    int64 `yaml:"total,omitempty"`
	Expire   int64 `yaml:"expire,omitempty"` // unix seconds
}

type PublicCatalog

type PublicCatalog struct {
	ActiveID       string          `json:"active_id,omitempty"`
	GlobalInterval string          `json:"global_interval"`
	Profiles       []PublicProfile `json:"profiles"`
}

type PublicProfile

type PublicProfile struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Enabled     bool      `json:"enabled"`
	AutoRefresh bool      `json:"auto_refresh"`
	Interval    string    `json:"interval"`
	Cached      bool      `json:"cached"`
	Generation  uint64    `json:"generation"`
	UpdatedAt   time.Time `json:"updated_at,omitempty"`
	LastError   string    `json:"last_error,omitempty"`
	// Traffic from subscription-userinfo (bytes). Omitted when unknown.
	Upload   int64 `json:"upload,omitempty"`
	Download int64 `json:"download,omitempty"`
	Total    int64 `json:"total,omitempty"`
	Expire   int64 `json:"expire,omitempty"`
}

type Receipt

type Receipt struct {
	Before Catalog
	After  Catalog
	// contains filtered or unexported fields
}

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(options SchedulerOptions) *Scheduler

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

type SchedulerOptions

type SchedulerOptions struct {
	Snapshot func() Catalog
	Refresh  func(context.Context, string) error
	Now      func() time.Time
	After    func(time.Duration) <-chan time.Time
	Jitter   func(string, time.Duration) time.Duration
	IdlePoll time.Duration
	MinRetry time.Duration
	MaxRetry time.Duration
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func Open

func Open(options ServiceOptions) (*Service, error)

func (*Service) Add

func (s *Service) Add(name, rawURL string) (Profile, error)

func (*Service) CachePath

func (s *Service) CachePath(id string) string

func (*Service) CommitRefresh

func (s *Service) CommitRefresh(prepared PreparedRefresh) (Receipt, error)

func (*Service) Mutate

func (s *Service) Mutate(mutate func(*Catalog) error) (Catalog, Catalog, error)

func (*Service) PrepareRefresh

func (s *Service) PrepareRefresh(ctx context.Context, id string) (PreparedRefresh, error)

func (*Service) ReadCache

func (s *Service) ReadCache(id string) ([]byte, Document, error)

func (*Service) Restore

func (s *Service) Restore(catalog Catalog) error

func (*Service) Rollback

func (s *Service) Rollback(receipt Receipt) error

func (*Service) Snapshot

func (s *Service) Snapshot() Catalog

type ServiceOptions

type ServiceOptions struct {
	CatalogPath string
	CacheDir    string
	Downloader  Fetcher
	Now         func() time.Time
}

type UserInfo

type UserInfo struct {
	Upload   int64
	Download int64
	Total    int64
	Expire   int64 // unix seconds; 0 if unknown
}

UserInfo is traffic/quota metadata from a provider's subscription-userinfo header. Values are bytes unless noted.

func ParseUserInfo

func ParseUserInfo(raw string) (UserInfo, bool)

ParseUserInfo parses headers like:

upload=123; download=456; total=789; expire=1710000000

func (UserInfo) Used

func (u UserInfo) Used() int64

Used returns upload+download traffic, clamped at zero.

Jump to

Keyboard shortcuts

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