storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 12 Imported by: 1 module, 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 storage provides atomic file operations, backup rotation, and path resolution for Aether colony data files. It replaces the shell-based atomic-write.sh and path resolution logic from aether-utils.sh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveAetherRoot

func ResolveAetherRoot() string

ResolveAetherRoot resolves the Aether root directory using a 3-tier fallback:

  1. AETHER_ROOT environment variable (if set)
  2. Git repository root (via git rev-parse --show-toplevel)
  3. Current working directory (fallback)

This matches the shell AETHER_ROOT resolution in atomic-write.sh:

if [[ -z "${AETHER_ROOT:-}" ]]; then
    if git rev-parse --show-toplevel >/dev/null 2>&1; then
        AETHER_ROOT="$(git rev-parse --show-toplevel)"
    else
        AETHER_ROOT="$(pwd)"
    fi
fi

func ResolveDataDir

func ResolveDataDir() string

ResolveDataDir resolves the colony data directory. If COLONY_DATA_DIR is set, it is returned directly. Otherwise, the default path AETHER_ROOT/.aether/data/ is returned.

This matches the COLONY_DATA_DIR override logic from the shell codebase where per-colony data directories are resolved via environment variable.

Types

type Store

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

Store provides thread-safe atomic file operations within a base directory. All file paths are resolved relative to basePath unless they are absolute.

func NewStore

func NewStore(basePath string) (*Store, error)

NewStore creates a new Store rooted at basePath. The directory is created if it does not exist.

func (*Store) AppendJSONL

func (s *Store) AppendJSONL(path string, entry interface{}) error

AppendJSONL appends a JSON entry as a single line to a JSONL file.

func (*Store) AtomicWrite

func (s *Store) AtomicWrite(path string, data []byte) error

AtomicWrite writes data to path atomically using a temporary file and rename. If path ends in .json, the content is validated as valid JSON before writing. On error, the temporary file is cleaned up.

func (*Store) BasePath

func (s *Store) BasePath() string

BasePath returns the store's root directory.

func (*Store) CreateBackup

func (s *Store) CreateBackup(path string) error

CreateBackup copies the file at path to a timestamped backup file. If the original file does not exist, it returns nil (nothing to back up). Backup files are named: path + ".bak.{timestamp}" matching the shell pattern.

func (*Store) LoadJSON

func (s *Store) LoadJSON(path string, dest interface{}) error

LoadJSON reads and unmarshals a JSON file.

func (*Store) LoadRawJSON

func (s *Store) LoadRawJSON(path string) ([]byte, error)

LoadRawJSON reads a JSON file and returns raw bytes.

func (*Store) ReadFile

func (s *Store) ReadFile(path string) ([]byte, error)

ReadFile reads raw file content from the store.

func (*Store) ReadJSONL

func (s *Store) ReadJSONL(path string) ([]json.RawMessage, error)

ReadJSONL reads all valid JSON lines from a JSONL file. Blank lines are skipped. Malformed lines are logged and skipped (not errored).

func (*Store) RotateBackups

func (s *Store) RotateBackups(basePath string) error

RotateBackups removes the oldest backup files beyond maxBackups. Backup files are identified by the glob pattern: path + ".bak.*" Files are sorted by modification time (newest first) and the oldest entries beyond the limit are deleted.

func (*Store) SaveJSON

func (s *Store) SaveJSON(path string, data interface{}) error

SaveJSON marshals data as formatted JSON and writes it atomically.

func (*Store) SaveRawJSON

func (s *Store) SaveRawJSON(path string, data []byte) error

SaveRawJSON writes raw bytes to a JSON file atomically.

Jump to

Keyboard shortcuts

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