Package store hosts a Store interface and its implementations.



This section is empty.


View Source
var (

	// ErrKeyNotFound is the error returned if key is not found in Store.
	ErrKeyNotFound = fmt.Errorf("key is not found")


func ValidateKey

func ValidateKey(key string) error

ValidateKey returns an error if the given key does not meet the requirement of the key format and length.


type FileStore

type FileStore struct {
	// contains filtered or unexported fields

FileStore is an implementation of the Store interface which stores data in files.

func (*FileStore) Delete

func (f *FileStore) Delete(key string) error

Delete deletes the key file.

func (*FileStore) List

func (f *FileStore) List() ([]string, error)

List returns all keys in the store.

func (*FileStore) Read

func (f *FileStore) Read(key string) ([]byte, error)

Read reads the data from the file named key.

func (*FileStore) Write

func (f *FileStore) Write(key string, data []byte) error

Write writes the given data to a file named key.

type Store

type Store interface {
	// key must contain one or more characters in [A-Za-z0-9]
	// Write writes data with key.
	Write(key string, data []byte) error
	// Read retrieves data with key
	// Read must return ErrKeyNotFound if key is not found.
	Read(key string) ([]byte, error)
	// Delete deletes data by key
	// Delete must not return error if key does not exist
	Delete(key string) error
	// List lists all existing keys.
	List() ([]string, error)

Store provides the interface for storing keyed data. Store must be thread-safe

func NewFileStore

func NewFileStore(path string, fs utilfs.Filesystem) (Store, error)

NewFileStore returns an instance of FileStore.