Documentation
¶
Overview ¶
Package persist provides codec-based file persistence for arbitrary state types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Codec ¶
type Codec interface {
// Encode writes the state to the writer.
Encode(w io.Writer, state any) error
// Decode reads the state from the reader.
Decode(r io.Reader, state any) error
// Extension returns the file extension for this codec (e.g., ".json", ".gob").
Extension() string
}
Codec defines how state is serialized and deserialized.
type GobCodec ¶
type GobCodec struct{}
GobCodec implements Codec using gob encoding.
type JSONCodec ¶
type JSONCodec struct {
// Indent specifies the indentation string. Empty string means compact JSON.
Indent string
}
JSONCodec implements Codec using JSON encoding with optional indentation.
func NewJSONCodec ¶
func NewJSONCodec() *JSONCodec
NewJSONCodec creates a JSON codec with pretty-printing (2-space indent).
type Persister ¶
type Persister[T any] struct { // contains filtered or unexported fields }
Persister handles I/O for a specific state type using a Codec.
func NewPersister ¶
NewPersister creates a persister with the given basename and codec.
Click to show internal directories.
Click to hide internal directories.