storage

package
v0.0.0-...-89805ac Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceKeySeparator = ":"
	Pong                  = "PONG"
	RedisScanBatchSize    = 1000
)
View Source
const (
	DBFilePrefix = "ssi-service"
)

Variables

This section is empty.

Functions

func IsStorageAvailable

func IsStorageAvailable(storage Type) bool

IsStorageAvailable determines whether a given storage provider is available for instantiation.

func MakeNamespace

func MakeNamespace(ns ...string) string

MakeNamespace takes a set of possible namespace values and combines them as a convention

func RegisterStorage

func RegisterStorage(storage ServiceStorage) error

RegisterStorage registers a storage dynamically by its Type.

Types

type BoltDB

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

func (*BoltDB) Close

func (b *BoltDB) Close() error

func (*BoltDB) Delete

func (b *BoltDB) Delete(namespace, key string) error

func (*BoltDB) DeleteNamespace

func (b *BoltDB) DeleteNamespace(namespace string) error

func (*BoltDB) Init

func (b *BoltDB) Init(options interface{}) error

Init instantiates a file-based storage instance for Bolt https://github.com/boltdb/bolt

func (*BoltDB) IsOpen

func (b *BoltDB) IsOpen() bool

IsOpen return if db was opened

func (*BoltDB) Read

func (b *BoltDB) Read(namespace, key string) ([]byte, error)

func (*BoltDB) ReadAll

func (b *BoltDB) ReadAll(namespace string) (map[string][]byte, error)

func (*BoltDB) ReadAllKeys

func (b *BoltDB) ReadAllKeys(namespace string) ([]string, error)

func (*BoltDB) ReadPrefix

func (b *BoltDB) ReadPrefix(namespace, prefix string) (map[string][]byte, error)

ReadPrefix does a prefix query within a namespace.

func (*BoltDB) Type

func (b *BoltDB) Type() Type

func (*BoltDB) URI

func (b *BoltDB) URI() string

URI return filepath of boltDB,

func (*BoltDB) Update

func (b *BoltDB) Update(namespace string, key string, values map[string]any) ([]byte, error)

func (*BoltDB) UpdateValueAndOperation

func (b *BoltDB) UpdateValueAndOperation(namespace, key string, updater Updater, opNamespace, opKey string, opUpdater ResponseSettingUpdater) (first, op []byte, err error)

UpdateValueAndOperation updates the value stored in (namespace,key) with the new values specified in the map. The updated value is then stored inside the (opNamespace, opKey), and the "done" value is set to true.

func (*BoltDB) Write

func (b *BoltDB) Write(namespace string, key string, value []byte) error

type FilterVarsMapper

type FilterVarsMapper interface {
	FilterVariablesMap() map[string]any
}

FilterVarsMapper is an interface that encapsulates the FilterVariablesMap method. This interface is meant to be implemented by any object that wants to include support for filtering.

type IncludeFunc

type IncludeFunc func(FilterVarsMapper) (bool, error)

IncludeFunc is a function that given a mapper object, decides whether the object should be included in the result.

func NewIncludeFunc

func NewIncludeFunc(filter filtering.Filter) (IncludeFunc, error)

NewIncludeFunc creates an IncludeFunc given a filter object. The result function is constructed as an evaluation of a cel program. The environment created matches standard construction of a filter. The result function runs the program evaluation on a given object that implements the FilterVarsMapper interface. Evaluation errors bubbled up so clients can decide what to do.

type RedisDB

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

func (*RedisDB) Close

func (b *RedisDB) Close() error

func (*RedisDB) Delete

func (b *RedisDB) Delete(namespace, key string) error

func (*RedisDB) DeleteNamespace

func (b *RedisDB) DeleteNamespace(namespace string) error

func (*RedisDB) Init

func (b *RedisDB) Init(i interface{}) error

func (*RedisDB) IsOpen

func (b *RedisDB) IsOpen() bool

func (*RedisDB) Read

func (b *RedisDB) Read(namespace, key string) ([]byte, error)

func (*RedisDB) ReadAll

func (b *RedisDB) ReadAll(namespace string) (map[string][]byte, error)

func (*RedisDB) ReadAllKeys

func (b *RedisDB) ReadAllKeys(namespace string) ([]string, error)

func (*RedisDB) ReadPrefix

func (b *RedisDB) ReadPrefix(namespace, prefix string) (map[string][]byte, error)

func (*RedisDB) Type

func (b *RedisDB) Type() Type

func (*RedisDB) URI

func (b *RedisDB) URI() string

func (*RedisDB) Update

func (b *RedisDB) Update(namespace string, key string, values map[string]any) ([]byte, error)

func (*RedisDB) UpdateValueAndOperation

func (b *RedisDB) UpdateValueAndOperation(namespace, key string, updater Updater, opNamespace, opKey string, opUpdater ResponseSettingUpdater) (first, op []byte, err error)

func (*RedisDB) Write

func (b *RedisDB) Write(namespace, key string, value []byte) error

func (*RedisDB) WriteMany

func (b *RedisDB) WriteMany(namespaces, keys []string, values [][]byte) error

type ResponseSettingUpdater

type ResponseSettingUpdater interface {
	Updater
	// SetUpdatedResponse sets the response that the Update method will later use to modify the data.
	SetUpdatedResponse([]byte)
}

type ServiceStorage

type ServiceStorage interface {
	Init(interface{}) error
	Type() Type
	URI() string
	IsOpen() bool
	Close() error
	Write(namespace, key string, value []byte) error
	Read(namespace, key string) ([]byte, error)
	ReadAll(namespace string) (map[string][]byte, error)
	ReadPrefix(namespace, prefix string) (map[string][]byte, error)
	ReadAllKeys(namespace string) ([]string, error)
	Delete(namespace, key string) error
	DeleteNamespace(namespace string) error
	Update(namespace string, key string, values map[string]any) ([]byte, error)
	UpdateValueAndOperation(namespace, key string, updater Updater, opNamespace, opKey string, opUpdater ResponseSettingUpdater) (first, op []byte, err error)
}

ServiceStorage describes the api for storage independent of DB providers

func GetStorage

func GetStorage(storageType Type) ServiceStorage

GetStorage fetches a previously registered storage by storage type.

func NewStorage

func NewStorage(storageProvider Type, option interface{}) (ServiceStorage, error)

NewStorage returns the instance of the given storageProvider. If it doesn't exist, then a default implementation is created with the given option parameter.

type Type

type Type string
const (
	Bolt  Type = "bolt"
	Redis Type = "redis"
)

func AvailableStorage

func AvailableStorage() []Type

AvailableStorage returns the supported storage providers.

type Updater

type Updater interface {
	Update(v []byte) ([]byte, error)
	// Validate runs after the data has been loaded from disk, but before the write is actually performed.
	Validate(v []byte) error
}

Updater encapsulates the Update method, which take a slice of bytes, and updates it before it's stored in the DB.

type UpdaterWithMap

type UpdaterWithMap struct {
	Values map[string]any
}

UpdaterWithMap is a json map based Updater implementation. The key/values from the map are used to update the unmarshalled JSON representation of the stored data.

func NewUpdater

func NewUpdater(values map[string]any) UpdaterWithMap

NewUpdater creates a new UpdaterWithMap with the given map.

func (UpdaterWithMap) Update

func (u UpdaterWithMap) Update(v []byte) ([]byte, error)

func (UpdaterWithMap) Validate

func (u UpdaterWithMap) Validate(_ []byte) error

Validate is a default implementation for UpdaterWithMap which does no validation. Users can pass embed UpdaterWithMap into a custom struct and redefine this method in order to have custom logic.

Jump to

Keyboard shortcuts

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