replaymsglog

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RootDir string
	Prefix  string
	MaxSize uint32
	Log     slog.Logger
}

Config is the configuration needed to initialize a Log object.

type ID

type ID uint64

ID is the ID of a message stored in a log. It is monotonically increasing, except when the log is entirely cleared (in which case, the set of IDs is reset).

func (ID) String

func (id ID) String() string

type Log

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

Log is a replay message log that stores messages (encoded as json objects) sequentially in a set of files.

Once messages are ack'd (by calling ClearUpTo), they are removed from the log.

One log instance (with a specific config) is meant to store only a single type of message.

The log functions are safe for concurrent access.

func New

func New(cfg Config) (*Log, error)

New creates a new message replay log.

func (*Log) ClearUpTo

func (l *Log) ClearUpTo(target ID) error

ClearUpTo removes all existing log entries up to (and including) the passed target ID.

func (*Log) ReadAfter

func (l *Log) ReadAfter(fromID ID, m interface{}, f func(ID) error) error

ReadAfter reads all entries stored after (i.e. NOT including) the passed fromID, calling the passed function for each entry.

If needed, it's the responsibility of the f function to reset or copy the contents of the m object.

Reads from this function may interact with calls to Store() such that it is undefined if a call to Store() concurrent to a call to ReadAfter will cause the message to be generated.

func (*Log) Store

func (l *Log) Store(v interface{}) (ID, error)

Store stores the given value in the log, as a JSON object. It returns the ID under which the message was stored, and which can be used to delete messages up to this one in a future call to ClearUpTo.

Jump to

Keyboard shortcuts

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