snapshot

package module
v0.0.0-...-dc1cc61 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 4 Imported by: ? 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

Overview

Package snapshot is gostructor's durable last-known-good store: a remote source (git, a config server) saves each good fetch to a Store and loads it back when the upstream is unreachable, so a remote hiccup doesn't take the service down. The version string (a commit SHA, a KV modify-index) lets the source tell whether the upstream has drifted from what it last stored.

Store is a two-method interface, so callers can keep snapshots anywhere; DirStore is the default on-disk implementation.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSnapshot = errors.New("gostructor/snapshot: no snapshot stored")

ErrNoSnapshot is returned by Load when the store holds nothing yet — a first run with the upstream unreachable, for instance. Callers test for it with errors.Is to distinguish "no last-known-good exists" from a real I/O error.

Functions

This section is empty.

Types

type DirStore

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

DirStore is the default file-backed Store. It keeps the payload and its version in two files under dir, writing each atomically (temp file + rename) so a crash mid-Save can never corrupt the last-known-good.

func NewDirStore

func NewDirStore(dir string) (*DirStore, error)

NewDirStore returns a DirStore rooted at dir, creating dir (and parents) if needed. A relative dir is resolved against the process working directory.

func (*DirStore) Load

func (s *DirStore) Load() (string, []byte, error)

Load reads back the payload and version, mapping a missing payload to ErrNoSnapshot.

func (*DirStore) Save

func (s *DirStore) Save(version string, data []byte) error

Save writes the version first, then the payload, each atomically. Payload last means a reader that races a Save either sees the whole previous snapshot or the whole new one — never a new payload tagged with the old version in a way that hides drift.

type Store

type Store interface {
	// Save records data as the current good snapshot, tagged with version (an
	// upstream identifier such as a commit SHA or modify-index). It should be
	// atomic from a reader's view — a concurrent Load never sees a half-written
	// payload.
	Save(version string, data []byte) error
	// Load returns the stored payload and the version it was saved under, or a
	// wrapped ErrNoSnapshot if nothing has been stored yet.
	Load() (version string, data []byte, err error)
}

Store persists the latest good configuration payload and the version it came from, and hands both back on request. Implementations must be safe for concurrent use: a Watch loop may Save while a reload Loads.

Jump to

Keyboard shortcuts

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