Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package state persists bentoo-tray's state: the feed ETag and serial, the read state and source of every notice, the pause end, the backoff and the earliest next fetch.

Index

Constants

View Source
const Format = 2

Format is the state file version this package writes.

Variables

View Source
var ErrCorrupt = errors.New("state file is damaged")

ErrCorrupt marks a state file that could not be parsed or carries an unknown format. Load has already moved it aside and returned a fresh state; the caller only has to WARN. Any other Load error is a real read failure.

Functions

This section is empty.

Types

type Record

type Record struct {
	Title    string    `json:"title"`
	Summary  string    `json:"summary"`
	URL      string    `json:"url"`
	Severity string    `json:"severity"`
	Type     string    `json:"type"`
	Source   string    `json:"source"`
	Read     bool      `json:"read"`
	Notified bool      `json:"notified"`
	LastSeen time.Time `json:"last_seen"`
	Updated  time.Time `json:"updated"`
}

Record is what is kept per notice. Summary lets a held or failed notification be rebuilt after a 304 or a restart. Source is "feed", "news", or "" for a record migrated from format 1, whose source is unknown.

type State

type State struct {
	Format     int               `json:"format"`
	ETag       string            `json:"etag"`
	Serial     int64             `json:"serial"`
	Notices    map[string]Record `json:"notices"`
	PauseUntil time.Time         `json:"pause_until"`
	Failures   int               `json:"failures"`
	// NextFetch is the earliest time the next fetch may run; zero means none is
	// scheduled.
	NextFetch time.Time `json:"next_fetch"`
	// Established reports that the first run is over: a check has accepted
	// a feed, or read the news when no feed is configured. A state without it
	// is a first run even once saved, so a first run can persist its backoff
	// and Retry-After without ending. A format 1 file loads
	// established: it was only ever written after the first run.
	Established bool `json:"established"`
	// Saved reports that a file was loaded or written; it is derived, never
	// stored.
	Saved bool `json:"-"`
}

State is everything bentoo-tray remembers between runs.

func (*State) Prune

func (s *State) Prune(now time.Time)

Prune drops the records not seen for more than 90 days.

type Store

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

Store reads and writes one state file.

func Open

func Open(path string) *Store

Open returns a Store for path; nothing is touched until Load or Save.

func (*Store) Load

func (s *Store) Load() (State, error)

Load reads the state. A missing file is a first run: a fresh state with Saved and Established false. A format 1 file is loaded with every record's Source left "", Established set (a format 1 tray wrote no state before its first run was over) and Format set to 2 in memory, so the next Save writes format 2. A format 2 file without "established" is a first run. A file that cannot be parsed or carries a format other than 1 or 2 is moved to <path>.corrupt-<unix time> and a fresh state is returned together with an error wrapping ErrCorrupt.

func (*Store) Save

func (s *Store) Save(st State) error

Save writes st atomically with mode 0600 in a 0700 directory, always in the current format. A failed save leaves the previous file intact.

Jump to

Keyboard shortcuts

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