store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package store is the mechanism layer: append-only JSONL channels on disk. One channel is one file under the store dir; a message is one JSON line. Appends are a single write(2) on an O_APPEND descriptor under an exclusive flock, so concurrent writers never interleave within a line. Readers take no lock at all — they resume from an opaque cursor (a byte offset) and stop cleanly at a torn final line.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadName         = errors.New("invalid channel name: use letters, digits, dot, dash, underscore (max 64)")
	ErrChannelNotFound = errors.New("channel not found")
	ErrBadCursor       = errors.New("invalid cursor")
	ErrEmptyFrom       = errors.New("from is required")
	ErrEmptyBody       = errors.New("body is required")
)

Sentinel errors callers branch on. Everything else is an internal failure.

Functions

This section is empty.

Types

type Info

type Info struct {
	Name         string    `json:"name"`
	LastActivity time.Time `json:"lastActivity"`
	SizeBytes    int64     `json:"sizeBytes"`
}

Info summarizes one channel for listings.

type Message

type Message struct {
	TS   time.Time `json:"ts"`
	From string    `json:"from"`
	Body string    `json:"body"`
}

Message is one line of a channel: who said what, when.

type Store

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

Store reads and appends channels under a single directory.

func New

func New(dir string) (*Store, error)

New opens (creating if needed) a store rooted at dir.

func (*Store) Dir

func (s *Store) Dir() string

Dir reports the resolved store directory.

func (*Store) List

func (s *Store) List() ([]Info, error)

List returns every channel in the store, most recently active first.

func (*Store) Post

func (s *Store) Post(name, from, body string) (Message, error)

Post appends one message to the named channel, creating the channel on first post. It returns the stored message with its server-side timestamp.

func (*Store) Read

func (s *Store) Read(name, cursor string, limit int) ([]Message, string, error)

Read returns messages after cursor (empty cursor = from the start) and the cursor to resume from. limit <= 0 means no limit. A torn final line — a writer mid-append — is excluded, and the returned cursor stops before it.

Jump to

Keyboard shortcuts

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