Documentation ¶
Index ¶
- Constants
- func IsStorageAvailable(storage Type) bool
- func Join(parts ...string) string
- func MakeNamespace(ns ...string) string
- func RegisterStorage(storage ServiceStorage) error
- func Update(ctx context.Context, s ServiceStorage, namespace, key string, m map[string]any) ([]byte, error)
- func UpdateValueAndOperation(ctx context.Context, s ServiceStorage, namespace, key string, updater Updater, ...) (first, op []byte, err error)
- type BoltDB
- func (b *BoltDB) Close() error
- func (b *BoltDB) Delete(_ context.Context, namespace, key string) error
- func (b *BoltDB) DeleteNamespace(_ context.Context, namespace string) error
- func (b *BoltDB) Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, _ []WatchKey) (any, error)
- func (b *BoltDB) Exists(_ context.Context, namespace, key string) (bool, error)
- func (b *BoltDB) Init(opts ...Option) error
- func (b *BoltDB) IsOpen() bool
- func (b *BoltDB) Read(_ context.Context, namespace, key string) ([]byte, error)
- func (b *BoltDB) ReadAll(_ context.Context, namespace string) (map[string][]byte, error)
- func (b *BoltDB) ReadAllKeys(_ context.Context, namespace string) ([]string, error)
- func (b *BoltDB) ReadPage(_ context.Context, namespace string, pageToken string, pageSize int) (map[string][]byte, string, error)
- func (b *BoltDB) ReadPrefix(_ context.Context, namespace, prefix string) (map[string][]byte, error)
- func (b *BoltDB) Type() Type
- func (b *BoltDB) URI() string
- func (b *BoltDB) Write(_ context.Context, namespace string, key string, value []byte) error
- func (b *BoltDB) WriteMany(_ context.Context, namespaces, keys []string, values [][]byte) error
- type BusinessLogicFunc
- type EncryptedWrapper
- func (e EncryptedWrapper) Close() error
- func (e EncryptedWrapper) Delete(ctx context.Context, namespace, key string) error
- func (e EncryptedWrapper) DeleteNamespace(ctx context.Context, namespace string) error
- func (e EncryptedWrapper) Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, watchKeys []WatchKey) (any, error)
- func (e EncryptedWrapper) Exists(ctx context.Context, namespace, key string) (bool, error)
- func (e EncryptedWrapper) Init(opts ...Option) error
- func (e EncryptedWrapper) IsOpen() bool
- func (e EncryptedWrapper) Read(ctx context.Context, namespace, key string) ([]byte, error)
- func (e EncryptedWrapper) ReadAll(ctx context.Context, namespace string) (map[string][]byte, error)
- func (e EncryptedWrapper) ReadAllKeys(ctx context.Context, namespace string) ([]string, error)
- func (e EncryptedWrapper) ReadPage(ctx context.Context, namespace string, pageToken string, pageSize int) (results map[string][]byte, nextPageToken string, err error)
- func (e EncryptedWrapper) ReadPrefix(ctx context.Context, namespace, prefix string) (map[string][]byte, error)
- func (e EncryptedWrapper) Type() Type
- func (e EncryptedWrapper) URI() string
- func (e EncryptedWrapper) Write(ctx context.Context, namespace, key string, value []byte) error
- func (e EncryptedWrapper) WriteMany(ctx context.Context, namespace, keys []string, values [][]byte) error
- type ExecContext
- type FilterVarsMapper
- type IncludeFunc
- type Option
- type OptionKey
- type QueryRow
- type RedisDB
- func (b *RedisDB) Close() error
- func (b *RedisDB) Delete(ctx context.Context, namespace, key string) error
- func (b *RedisDB) DeleteNamespace(ctx context.Context, namespace string) error
- func (b *RedisDB) Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, watchKeys []WatchKey) (any, error)
- func (b *RedisDB) Exists(ctx context.Context, namespace, key string) (bool, error)
- func (b *RedisDB) Init(opts ...Option) error
- func (b *RedisDB) IsOpen() bool
- func (b *RedisDB) Read(ctx context.Context, namespace, key string) ([]byte, error)
- func (b *RedisDB) ReadAll(ctx context.Context, namespace string) (map[string][]byte, error)
- func (b *RedisDB) ReadAllKeys(ctx context.Context, namespace string) ([]string, error)
- func (b *RedisDB) ReadPage(ctx context.Context, namespace string, pageToken string, pageSize int) (map[string][]byte, string, error)
- func (b *RedisDB) ReadPrefix(ctx context.Context, namespace, prefix string) (map[string][]byte, error)
- func (b *RedisDB) Type() Type
- func (b *RedisDB) URI() string
- func (b *RedisDB) Update(ctx context.Context, namespace string, key string, values map[string]any) ([]byte, error)
- func (b *RedisDB) UpdateValueAndOperation(ctx context.Context, namespace, key string, updater Updater, ...) (first, op []byte, err error)
- func (b *RedisDB) Write(ctx context.Context, namespace, key string, value []byte) error
- func (b *RedisDB) WriteMany(ctx context.Context, namespaces, keys []string, values [][]byte) error
- type ResponseSettingUpdater
- type SQLDB
- func (s *SQLDB) Close() error
- func (s *SQLDB) Delete(ctx context.Context, namespace, key string) error
- func (s *SQLDB) DeleteNamespace(ctx context.Context, namespace string) error
- func (s *SQLDB) Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, _ []WatchKey) (any, error)
- func (s *SQLDB) Exists(ctx context.Context, namespace, key string) (bool, error)
- func (s *SQLDB) Init(opts ...Option) error
- func (s *SQLDB) IsOpen() bool
- func (s *SQLDB) Read(ctx context.Context, namespace, key string) ([]byte, error)
- func (s *SQLDB) ReadAll(ctx context.Context, namespace string) (map[string][]byte, error)
- func (s *SQLDB) ReadAllKeys(ctx context.Context, namespace string) ([]string, error)
- func (s *SQLDB) ReadPage(ctx context.Context, namespace string, pageToken string, pageSize int) (results map[string][]byte, nextPageToken string, err error)
- func (s *SQLDB) ReadPrefix(ctx context.Context, namespace, prefix string) (map[string][]byte, error)
- func (s *SQLDB) Type() Type
- func (s *SQLDB) URI() string
- func (s *SQLDB) Update(ctx context.Context, namespace string, key string, values map[string]any) ([]byte, error)
- func (s *SQLDB) UpdateValueAndOperation(ctx context.Context, namespace, key string, updater Updater, ...) (first, op []byte, err error)
- func (s *SQLDB) Write(ctx context.Context, namespace, key string, value []byte) error
- func (s *SQLDB) WriteMany(ctx context.Context, namespaces, keys []string, values [][]byte) error
- type ServiceStorage
- type Tx
- type Type
- type Updater
- type UpdaterWithMap
- type WatchKey
Constants ¶
const ( Pong = "PONG" RedisScanBatchSize = 1000 MaxElapsedTime = 6 * time.Second RedisAddressOption OptionKey = "redis-address-option" )
const ( Bolt Type = "bolt" DatabaseSQL Type = "database_sql" Redis Type = "redis" PasswordOption OptionKey = "storage-password-option" )
Variables ¶
This section is empty.
Functions ¶
func IsStorageAvailable ¶
IsStorageAvailable determines whether a given storage provider is available for instantiation.
func MakeNamespace ¶
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.
func UpdateValueAndOperation ¶
func UpdateValueAndOperation(ctx context.Context, s ServiceStorage, 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.
Types ¶
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
func (*BoltDB) DeleteNamespace ¶
func (*BoltDB) Execute ¶
func (b *BoltDB) Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, _ []WatchKey) (any, error)
Execute runs the provided function within a transaction. Any failure during execution results in a rollback. It is recommended to not open transactions within businessLogicFunc, as there are situation in which the interplay between transactions may cause deadlocks.
func (*BoltDB) Init ¶
Init instantiates a file-based storage instance for Bolt https://github.com/boltdb/bolt
func (*BoltDB) ReadAllKeys ¶
func (*BoltDB) ReadPrefix ¶
ReadPrefix does a prefix query within a namespace.
type EncryptedWrapper ¶
type EncryptedWrapper struct {
// contains filtered or unexported fields
}
func NewEncryptedWrapper ¶
func NewEncryptedWrapper(s ServiceStorage, encrypter encryption.Encrypter, decrypter encryption.Decrypter) *EncryptedWrapper
func (EncryptedWrapper) Close ¶
func (e EncryptedWrapper) Close() error
func (EncryptedWrapper) Delete ¶
func (e EncryptedWrapper) Delete(ctx context.Context, namespace, key string) error
func (EncryptedWrapper) DeleteNamespace ¶
func (e EncryptedWrapper) DeleteNamespace(ctx context.Context, namespace string) error
func (EncryptedWrapper) Execute ¶
func (e EncryptedWrapper) Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, watchKeys []WatchKey) (any, error)
func (EncryptedWrapper) Init ¶
func (e EncryptedWrapper) Init(opts ...Option) error
func (EncryptedWrapper) IsOpen ¶
func (e EncryptedWrapper) IsOpen() bool
func (EncryptedWrapper) ReadAllKeys ¶
func (EncryptedWrapper) ReadPrefix ¶
func (EncryptedWrapper) Type ¶
func (e EncryptedWrapper) Type() Type
func (EncryptedWrapper) URI ¶
func (e EncryptedWrapper) URI() string
type ExecContext ¶
type FilterVarsMapper ¶
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 OptionKey ¶
type OptionKey string
OptionKey uniquely represents an option to be used in a storage provider
const ( DBFilePrefix = "ssi-service" BoltDBFilePathOption OptionKey = "boltdb-filepath-option" )
type RedisDB ¶
type RedisDB struct {
// contains filtered or unexported fields
}
func (*RedisDB) DeleteNamespace ¶
func (*RedisDB) ReadAllKeys ¶
func (*RedisDB) ReadPrefix ¶
func (*RedisDB) UpdateValueAndOperation ¶
type ResponseSettingUpdater ¶
type SQLDB ¶
type SQLDB struct {
// contains filtered or unexported fields
}
func (*SQLDB) DeleteNamespace ¶
func (*SQLDB) ReadAllKeys ¶
func (*SQLDB) ReadPrefix ¶
func (*SQLDB) UpdateValueAndOperation ¶
type ServiceStorage ¶
type ServiceStorage interface { Init(opts ...Option) error Type() Type URI() string IsOpen() bool Close() error Write(ctx context.Context, namespace, key string, value []byte) error WriteMany(ctx context.Context, namespace, key []string, value [][]byte) error Read(ctx context.Context, namespace, key string) ([]byte, error) Exists(ctx context.Context, namespace, key string) (bool, error) ReadAll(ctx context.Context, namespace string) (map[string][]byte, error) // ReadPage returns a page of elements. When pageSize == -1, all elements are returned. Results are returned // starting from the pageToken. pageToken may be empty. // Note that pageSize is a hint and may not be enforced by the DB implementation. This is intentional, as some DBs // do not have a way to enforce this (e.g. Redis), and the DB may decide to return everything in some cases. A more // detailed explanation is available at https://redis.io/commands/scan/, section // "Why SCAN may return all the items of an aggregate data type in a single call?". ReadPage(ctx context.Context, namespace string, pageToken string, pageSize int) (results map[string][]byte, nextPageToken string, err error) ReadPrefix(ctx context.Context, namespace, prefix string) (map[string][]byte, error) ReadAllKeys(ctx context.Context, namespace string) ([]string, error) Delete(ctx context.Context, namespace, key string) error DeleteNamespace(ctx context.Context, namespace string) error Execute(ctx context.Context, businessLogicFunc BusinessLogicFunc, watchKeys []WatchKey) (any, 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, opts ...Option) (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
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 ¶
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) 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.