store

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package store defines and implements data store for sqlite and in-memory

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoadRejected = errors.New("message expired or deleted")
	ErrSaveRejected = errors.New("can't save message")
)

Error messages

Functions

func GenerateID

func GenerateID() string

GenerateID creates a 12-character base62 random ID using crypto/rand. Uses rejection sampling to avoid modulo bias.

Types

type Message

type Message struct {
	Key       string
	Exp       time.Time
	Data      []byte
	PinHash   string
	Errors    int
	ClientEnc bool // true if client-side encrypted (UI), false if server-side (API)
}

Message with key and exp. time

type SQLite

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

SQLite implements store.Engine with SQLite database

func NewInMemory

func NewInMemory(cleanupDuration time.Duration) *SQLite

NewInMemory creates an ephemeral in-memory SQLite store. Each call creates an isolated database using a unique URI.

func NewSQLite

func NewSQLite(dbFile string, cleanupDuration time.Duration) (*SQLite, error)

NewSQLite creates a persistent SQLite-based store

func (*SQLite) Close

func (s *SQLite) Close() error

Close closes the database connection and stops the cleaner goroutine

func (*SQLite) IncErr

func (s *SQLite) IncErr(ctx context.Context, key string) (int, error)

IncErr atomically increments the error count and returns new value

func (*SQLite) Load

func (s *SQLite) Load(ctx context.Context, key string) (*Message, error)

Load retrieves message by key

func (*SQLite) Remove

func (s *SQLite) Remove(ctx context.Context, key string) error

Remove deletes message by key

func (*SQLite) Save

func (s *SQLite) Save(ctx context.Context, msg *Message) error

Save stores message in the database

Jump to

Keyboard shortcuts

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