Data Storage:
At LightningUserVault, we value flexibility. With our Storage interface, you can easily integrate a variety of storage systems. We currently support Pebble
for key-value storage and PostgreSQL
for SQL, but the architecture allows for easy expansion.
✅ Currently Supported:
Pebble
(Key-Value)PostgreSQL
(SQL)
🔌 Storage Interface:
If you're interested in adding more storage options, here's the interface to guide you:
type Storage interface {
// Set stores a value and returns user ID and an error if any issue occurs during the operation
Set(value string) (int64, error)
// Get retrieves the value for a given user ID and returns an error if any issue occurs during the operation
Get(key int64) (*common.User, error)
// Close closes storage instance
Close() error
}
🧪 Mock Implementations for Testing
For developers and testers, we offer mock implementation of database interface
package mocks
import "github.com/Aleksao998/LightningUserVault/core/common"
type (
getDelegate func(key int64) (*common.User, error)
setDelegate func(value string) (int64, error)
closeDelegate func() error
)
type MockStorage struct {
GetFn getDelegate
SetFn setDelegate
CloseFn closeDelegate
}
func (m *MockStorage) Get(key int64) (*common.User, error) {
if m.GetFn != nil {
return m.GetFn(key)
}
return nil, nil
}
func (m *MockStorage) Set(value string) (int64, error) {
if m.SetFn != nil {
return m.SetFn(value)
}
return 0, nil
}
func (m *MockStorage) Close() error {
if m.CloseFn != nil {
return m.CloseFn()
}
return nil
}
Usage example:
mockStorage := &storageMock.MockStorage{
GetFn: func(key int64) (*common.User, error) {
return nil, errUserNotFound
},
SetFn: func(value string) (int64, error) {
return 0, errInternal
},
}
Last updated