store

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package store keeps the last valid snapshot of each source on disk, shared by the sync and API processes and kept across restarts.

File format, version 1

Each source has one file, <name>.snapshot, where name is the source lowercased with every run of characters other than a-z and 0-9 turned into a single "-" ("AMF listes blanches" is amf-listes-blanches.snapshot). The file holds two parts, both UTF-8 JSON:

  • an envelope on the first line, ended by "\n": {"format":"arnakoff-snapshot","version":1,"sha256":"<hex>"}, where sha256 is the hex SHA-256 digest of the body;
  • the body, the rest of the file: {"source":"AMF", "fetched_at":"<RFC 3339>","newest":"<RFC 3339>","header":[...], "rows":[[...],...]}; newest is left out when the source dates no entry.

A file whose envelope, digest or body does not check out, or that holds another source, is rejected with ErrCorrupt; one of another version with ErrVersion. A change to the body or envelope bumps the version.

A file is written to a temporary file in the same directory, synced, then renamed over the previous one, and the directory is synced on Unix: a reader sees the previous file or the new one, never part of one.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCorrupt    = errors.New("corrupt snapshot file")
	ErrVersion    = errors.New("unsupported snapshot format version")
	ErrSourceName = errors.New("source name gives no file name")
)

Store errors, checked with errors.Is.

Functions

This section is empty.

Types

type Disk

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

Disk stores one snapshot file per source in a directory. It implements app.SnapshotStore and is safe for concurrent use, also across processes.

func NewDisk

func NewDisk(dir string) (*Disk, error)

NewDisk returns a Disk storing its files in dir, created if missing.

func (*Disk) Load

func (d *Disk) Load(ctx context.Context, source domain.Source) (domain.Snapshot, error)

Load returns the stored snapshot of source, app.ErrNoSnapshot when there is none, or ErrCorrupt or ErrVersion when its file does not check out.

func (*Disk) Save

func (d *Disk) Save(ctx context.Context, s domain.Snapshot) error

Save durably replaces the stored snapshot of s.Source: readers see the previous file or the new one, never part of one.

Jump to

Keyboard shortcuts

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