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 ¶
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 ¶
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 ¶
Load reads back the payload and version, mapping a missing payload to ErrNoSnapshot.
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.