store

package
v1.9.11 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package store hosts a Store interface and its implementations.

Index

Constants

This section is empty.

Variables

View Source
var (

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

Functions

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.

Types

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.

Jump to

Keyboard shortcuts

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