Added the PrefixDb interface
This commit is contained in:
parent
dc782d87a8
commit
5d294b663c
@ -10,6 +10,14 @@ const (
|
||||
DATATYPE_USERSUB = 64
|
||||
)
|
||||
|
||||
// PrefixDb interface abstracts the database operations.
|
||||
type PrefixDb interface {
|
||||
Get(ctx context.Context, key []byte) ([]byte, error)
|
||||
Put(ctx context.Context, key []byte, val []byte) error
|
||||
}
|
||||
|
||||
var _ PrefixDb = (*SubPrefixDb)(nil)
|
||||
|
||||
type SubPrefixDb struct {
|
||||
store db.Db
|
||||
pfx []byte
|
||||
@ -29,11 +37,7 @@ func (s *SubPrefixDb) toKey(k []byte) []byte {
|
||||
func (s *SubPrefixDb) Get(ctx context.Context, key []byte) ([]byte, error) {
|
||||
s.store.SetPrefix(DATATYPE_USERSUB)
|
||||
key = s.toKey(key)
|
||||
v, err := s.store.Get(ctx, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
return s.store.Get(ctx, key)
|
||||
}
|
||||
|
||||
func (s *SubPrefixDb) Put(ctx context.Context, key []byte, val []byte) error {
|
||||
|
Loading…
Reference in New Issue
Block a user