localstate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: GPL-3.0 Imports: 7 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

Overview

Package localstate persists small local JSON documents with explicit commit outcomes at the atomic rename boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSON

func MarshalJSON(value any) ([]byte, error)

MarshalJSON returns the exact indented bytes written by ReplaceJSON.

func MarshalJSONCompact

func MarshalJSONCompact(value any) ([]byte, error)

MarshalJSONCompact returns the exact bytes written by ReplaceJSONCompact. Raw JSON payloads retain their accepted byte representation without HTML escaping or presentation whitespace that could exceed their read limits.

Types

type CommitError

type CommitError struct {
	Outcome CommitOutcome
	Op      string
	Err     error
}

CommitError preserves the truthful outcome when a replacement operation fails. Its text intentionally contains only the operation, never state data.

func (*CommitError) Error

func (e *CommitError) Error() string

func (*CommitError) Unwrap

func (e *CommitError) Unwrap() error

type CommitOutcome

type CommitOutcome string

CommitOutcome identifies whether replacement bytes crossed the atomic rename boundary.

const (
	NotCommitted                 CommitOutcome = "not_committed"
	Committed                    CommitOutcome = "committed"
	CommittedDurabilityUncertain CommitOutcome = "committed_durability_uncertain"
)

func RemoveAndSync

func RemoveAndSync(path string) (CommitOutcome, error)

RemoveAndSync removes one local-state file and fsyncs its parent directory. Its outcome identifies whether deletion crossed the filesystem boundary.

func ReplaceJSON

func ReplaceJSON(path string, value any) (CommitOutcome, error)

ReplaceJSON atomically replaces path with one JSON document. Files are mode 0600 and newly created directories are mode 0700.

func ReplaceJSONCompact

func ReplaceJSONCompact(path string, value any) (CommitOutcome, error)

ReplaceJSONCompact atomically replaces path without adding presentation whitespace. It is suitable for stores whose byte bounds include envelopes.

func (CommitOutcome) IsCommitted

func (o CommitOutcome) IsCommitted() bool

IsCommitted reports whether the new bytes were renamed into place.

Jump to

Keyboard shortcuts

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