store

package module
v0.0.0-...-afbec78 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: BSD-3-Clause Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug() bool

Debug toggles (enables/disables) debug output through Logger and returns either true if enabled or respectively false if disabled.

func Type

func Type(data any) reflect.Kind

Type determines the type of given data and returns the kind value.

Types

type Content

type Content struct {
	Name any
	Data any
	Date time.Time
}

Content contains the actual data.

type List

type List[Key comparable] []Summary[Key]

List is replied on List() calls with metadata.

type Portions

type Portions func(key any) int

Portions to split the store into map divisions by.

type Snapshot

type Snapshot struct {
	Date time.Time
	Data []*Content
}

Snapshot contains the exported data and a timestamp of creation.

type Store

type Store[Key comparable, Value any] struct {
	// Logger adds a prefix of "store: " by default.
	Logger *log.Logger
	// contains filtered or unexported fields
}

Store is the main datatype that holds runtime.

func New

func New[Key comparable, Value any]() *Store[Key, Value]

New creates a new instance of store.

func (*Store[Key, Value]) Delete

func (s *Store[Key, Value]) Delete(key Key) bool

Delete removes the item called by the given key and return true if the key existed.

func (*Store[Key, Value]) Export

func (s *Store[Key, Value]) Export() *Snapshot

Export allows snapshots of store.

func (*Store[Key, Value]) Get

func (s *Store[Key, Value]) Get(key Key) (Value, bool)

Get looks up items by the given key and returns the data and a found boolean.

func (*Store[Key, Value]) GetBool

func (s *Store[Key, Value]) GetBool(key Key) bool

GetBool looks up items by the given key and returns the data as boolean.

func (*Store[Key, Value]) GetBools

func (s *Store[Key, Value]) GetBools(key Key) []bool

GetBools looks up items by the given key and returns the data as []bool.

func (*Store[Key, Value]) GetByte

func (s *Store[Key, Value]) GetByte(key Key) byte

GetByte looks up items by the given key and returns the data as byte.

func (*Store[Key, Value]) GetBytes

func (s *Store[Key, Value]) GetBytes(key Key) []byte

GetBytes looks up items by the given key and returns the data as []byte.

func (*Store[Key, Value]) GetFloat64

func (s *Store[Key, Value]) GetFloat64(key Key) float64

GetFloat64 looks up items by the given key and returns the data as float64.

func (*Store[Key, Value]) GetFloat64s

func (s *Store[Key, Value]) GetFloat64s(key Key) []float64

GetFloat64s looks up items by the given key and returns the data as []float64.

func (*Store[Key, Value]) GetInt

func (s *Store[Key, Value]) GetInt(key Key) int

GetInt looks up items by the given key and returns the data as int.

func (*Store[Key, Value]) GetInt64

func (s *Store[Key, Value]) GetInt64(key Key) int64

GetInt64 looks up items by the given key and returns the data as int64.

func (*Store[Key, Value]) GetInt64s

func (s *Store[Key, Value]) GetInt64s(key Key) []int64

GetInt64s looks up items by the given key and returns the data as []int64.

func (*Store[Key, Value]) GetInts

func (s *Store[Key, Value]) GetInts(key Key) []int

GetInts looks up items by the given key and returns the data as []int.

func (*Store[Key, Value]) GetString

func (s *Store[Key, Value]) GetString(key Key) string

GetString looks up items by the given key and returns the data as string.

func (*Store[Key, Value]) GetStrings

func (s *Store[Key, Value]) GetStrings(key Key) []string

GetStrings looks up items by the given key and returns the data as []string.

func (*Store[Key, Value]) Import

func (s *Store[Key, Value]) Import(snap *Snapshot) *Store[Key, Value]

Import will simply add snapshot data to store.

func (*Store[Key, Value]) List

func (s *Store[Key, Value]) List() List[Key]

List returns all keys with corresponding last change date values in the store.

func (*Store[Key, Value]) Set

func (s *Store[Key, Value]) Set(key, data any) (bool, error)

Set adds a new or overwrites an existing item in the store with the given key and data and returns the boolean value of replace.

func (*Store[Key, Value]) State

func (s *Store[Key, Value]) State(key Key) (time.Time, bool)

State looks up the item by the given key and returns the change date and a found boolean.

func (*Store[Key, Value]) Wipe

func (s *Store[Key, Value]) Wipe() bool

Wipe removes all entries from the store.

func (*Store[Key, Value]) WithPortions

func (s *Store[Key, Value]) WithPortions(p Portions) *Store[Key, Value]

WithPortions replaces the default Portions function with p if this call comes to an empty store.

type Summary

type Summary[Key comparable] struct {
	Key  Key
	Date time.Time
}

Jump to

Keyboard shortcuts

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