代码拉取完成,页面将自动刷新
package kv
import (
"gitee.com/aiou-official/go-aiou/db/kv/leveldb"
)
// StorageType is the type of storage, include leveldb and rocksdb
type StorageType uint8
// Storage type constant
const (
_ StorageType = iota
LevelDBStorage
)
// StorageBackend is the storage backend interface
type StorageBackend interface {
Get(key []byte) ([]byte, error)
Put(key []byte, value []byte) error
Has(key []byte) (bool, error)
Delete(key []byte) error
Keys(prefix []byte) ([][]byte, error)
KeysByRange(from []byte, to []byte, limit int) ([][]byte, error)
BeginBatch() error
CommitBatch() error
Size() (int64, error)
Close() error
NewIteratorByPrefix(prefix []byte) interface{}
}
// Storage is a kv database
type Storage struct {
StorageBackend
}
// NewStorage return the storage of the specify type
func NewStorage(path string, t StorageType) (*Storage, error) {
switch t {
case LevelDBStorage:
sb, err := leveldb.NewDB(path)
if err != nil {
return nil, err
}
return &Storage{StorageBackend: sb}, nil
default:
sb, err := leveldb.NewDB(path)
if err != nil {
return nil, err
}
return &Storage{StorageBackend: sb}, nil
}
}
// NewIteratorByPrefix returns a new iterator by prefix
func (s *Storage) NewIteratorByPrefix(prefix []byte) *Iterator {
ib := s.StorageBackend.NewIteratorByPrefix(prefix).(IteratorBackend)
return &Iterator{
IteratorBackend: ib,
}
}
// IteratorBackend is the storage iterator backend
type IteratorBackend interface {
Next() bool
Key() []byte
Value() []byte
Error() error
Release()
}
// Iterator is the storage iterator
type Iterator struct {
IteratorBackend
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。