store

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

Error messages

Functions

func Key

func Key(ts time.Time, key string) string

Key makes store key with ts prefix

Types

type Bolt

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

Bolt implements store.Engine with boltdb

func NewBolt

func NewBolt(dbFile string, cleanupDuration time.Duration) (*Bolt, error)

NewBolt makes persistent boltdb based store

func (*Bolt) IncErr

func (s *Bolt) IncErr(key string) (count int, err error)

IncErr increments error count

func (*Bolt) Load

func (s *Bolt) Load(key string) (result *Message, err error)

Load by key, removes on first access, checks expire

func (*Bolt) Remove

func (s *Bolt) Remove(key string) (err error)

Remove by key

func (*Bolt) Save

func (s *Bolt) Save(msg *Message) (err error)

Save with autogenerated ts-uuid as a key. ts prefix for bolt range query

type InMemory

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

InMemory implements store.Interface with concurrent map

func NewInMemory

func NewInMemory(cleanupDuration time.Duration) *InMemory

NewInMemory makes new store with max duration

func (*InMemory) IncErr

func (s *InMemory) IncErr(key string) (count int, err error)

IncErr increments error count

func (*InMemory) Load

func (s *InMemory) Load(key string) (result *Message, err error)

Load by key, removes on first access, checks expire

func (*InMemory) Remove

func (s *InMemory) Remove(key string) (err error)

Remove by key

func (*InMemory) Save

func (s *InMemory) Save(msg *Message) (err error)

Save to map with autogenerated uuid as a key

type Message

type Message struct {
	Key     string
	Exp     time.Time
	Data    []byte
	PinHash string
	Errors  int
}

Message with key and exp. time

Jump to

Keyboard shortcuts

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