memkv

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package memkv implements an in-memory key/value store with hierarchical path-based operations designed for template rendering.

Originally from github.com/kelseyhightower/memkv, internalized for maintenance.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExist is returned when a key does not exist in the store.
	ErrNotExist = errors.New("key does not exist")
	// ErrNoMatch is returned when no keys match a pattern.
	ErrNoMatch = errors.New("no keys match")
)

Functions

This section is empty.

Types

type KVPair

type KVPair struct {
	Key   string
	Value string
}

KVPair represents a key-value pair stored in the Store.

type KVPairs

type KVPairs []KVPair

KVPairs is a slice of KVPair that implements sort.Interface for sorting by key.

func (KVPairs) Len

func (ks KVPairs) Len() int

Len returns the number of pairs.

func (KVPairs) Less

func (ks KVPairs) Less(i, j int) bool

Less reports whether the pair at index i should sort before the pair at index j.

func (KVPairs) Swap

func (ks KVPairs) Swap(i, j int)

Swap swaps the pairs at indices i and j.

type KeyError

type KeyError struct {
	Key string
	Err error
}

KeyError wraps an error with the associated key.

func (*KeyError) Error

func (e *KeyError) Error() string

func (*KeyError) Unwrap

func (e *KeyError) Unwrap() error

Unwrap returns the underlying error for use with errors.Is/As.

type Store

type Store struct {
	FuncMap map[string]interface{}
	// contains filtered or unexported fields
}

Store is an in-memory key-value store safe for concurrent access. It provides hierarchical path-based operations suitable for template rendering.

func New

func New() *Store

New creates and initializes a new Store with template functions pre-registered.

func (*Store) Del

func (s *Store) Del(key string)

Del deletes the KVPair associated with key.

func (*Store) Exists

func (s *Store) Exists(key string) bool

Exists checks for the existence of key in the store.

func (*Store) Get

func (s *Store) Get(key string) (KVPair, error)

Get returns the KVPair associated with key. If the key does not exist, it returns an error wrapping ErrNotExist.

func (*Store) GetAll

func (s *Store) GetAll(pattern string) (KVPairs, error)

GetAll returns all KVPairs with keys matching the given pattern. The pattern syntax is the same as path.Match. Returns an empty slice (not an error) if no keys match.

func (*Store) GetAllValues

func (s *Store) GetAllValues(pattern string) ([]string, error)

GetAllValues returns all values for keys matching the given pattern. The pattern syntax is the same as path.Match. Returns an empty slice (not an error) if no keys match.

func (*Store) GetValue

func (s *Store) GetValue(key string, defaultValue ...string) (string, error)

GetValue returns the value associated with key. If the key does not exist and a default is provided, the default is returned. Otherwise, it returns an error wrapping ErrNotExist.

func (*Store) List

func (s *Store) List(filePath string) []string

List returns all entry names directly under the given path. This includes both leaf keys and intermediate path components.

func (*Store) ListDir

func (s *Store) ListDir(filePath string) []string

ListDir returns all directory names directly under the given path. Unlike List, this only returns intermediate path components, not leaf keys.

func (*Store) Purge

func (s *Store) Purge()

Purge removes all entries from the store.

func (*Store) Set

func (s *Store) Set(key, value string)

Set stores a key-value pair in the store.

Jump to

Keyboard shortcuts

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