Upgrade linter rules

This commit is contained in:
arnaucube
2020-12-15 19:33:14 +01:00
parent 730707e565
commit e5a3d7e049
10 changed files with 244 additions and 178 deletions

View File

@@ -11,20 +11,20 @@ import (
"github.com/syndtr/goleveldb/leveldb/util"
)
// LevelDbStorage implements the db.Storage interface
type LevelDbStorage struct {
// Storage implements the db.Storage interface
type Storage struct {
ldb *leveldb.DB
prefix []byte
}
// LevelDbStorageTx implements the db.Tx interface
type LevelDbStorageTx struct {
*LevelDbStorage
// StorageTx implements the db.Tx interface
type StorageTx struct {
*Storage
cache db.KvMap
}
// NewLevelDbStorage returns a new LevelDbStorage
func NewLevelDbStorage(path string, errorIfMissing bool) (*LevelDbStorage, error) {
// NewLevelDbStorage returns a new Storage
func NewLevelDbStorage(path string, errorIfMissing bool) (*Storage, error) {
o := &opt.Options{
ErrorIfMissing: errorIfMissing,
}
@@ -32,7 +32,7 @@ func NewLevelDbStorage(path string, errorIfMissing bool) (*LevelDbStorage, error
if err != nil {
return nil, err
}
return &LevelDbStorage{ldb, []byte{}}, nil
return &Storage{ldb, []byte{}}, nil
}
type storageInfo struct {
@@ -41,7 +41,7 @@ type storageInfo struct {
}
// Info implements the method Info of the interface db.Storage
func (l *LevelDbStorage) Info() string {
func (l *Storage) Info() string {
snapshot, err := l.ldb.GetSnapshot()
if err != nil {
return err.Error()
@@ -72,17 +72,17 @@ func (l *LevelDbStorage) Info() string {
}
// WithPrefix implements the method WithPrefix of the interface db.Storage
func (l *LevelDbStorage) WithPrefix(prefix []byte) db.Storage {
return &LevelDbStorage{l.ldb, db.Concat(l.prefix, prefix)}
func (l *Storage) WithPrefix(prefix []byte) db.Storage {
return &Storage{l.ldb, db.Concat(l.prefix, prefix)}
}
// NewTx implements the method NewTx of the interface db.Storage
func (l *LevelDbStorage) NewTx() (db.Tx, error) {
return &LevelDbStorageTx{l, make(db.KvMap)}, nil
func (l *Storage) NewTx() (db.Tx, error) {
return &StorageTx{l, make(db.KvMap)}, nil
}
// Get retreives a value from a key in the db.Storage
func (l *LevelDbStorage) Get(key []byte) ([]byte, error) {
func (l *Storage) Get(key []byte) ([]byte, error) {
v, err := l.ldb.Get(db.Concat(l.prefix, key[:]), nil)
if err == errors.ErrNotFound {
return nil, db.ErrNotFound
@@ -91,7 +91,7 @@ func (l *LevelDbStorage) Get(key []byte) ([]byte, error) {
}
// Iterate implements the method Iterate of the interface db.Storage
func (l *LevelDbStorage) Iterate(f func([]byte, []byte) (bool, error)) error {
func (l *Storage) Iterate(f func([]byte, []byte) (bool, error)) error {
// FIXME: Use the prefix!
snapshot, err := l.ldb.GetSnapshot()
if err != nil {
@@ -112,7 +112,7 @@ func (l *LevelDbStorage) Iterate(f func([]byte, []byte) (bool, error)) error {
}
// Get retreives a value from a key in the interface db.Tx
func (tx *LevelDbStorageTx) Get(key []byte) ([]byte, error) {
func (tx *StorageTx) Get(key []byte) ([]byte, error) {
var err error
fullkey := db.Concat(tx.prefix, key)
@@ -130,14 +130,14 @@ func (tx *LevelDbStorageTx) Get(key []byte) ([]byte, error) {
}
// Put saves a key:value into the db.Storage
func (tx *LevelDbStorageTx) Put(k, v []byte) error {
func (tx *StorageTx) Put(k, v []byte) error {
tx.cache.Put(db.Concat(tx.prefix, k[:]), v)
return nil
}
// Add implements the method Add of the interface db.Tx
func (tx *LevelDbStorageTx) Add(atx db.Tx) error {
ldbtx := atx.(*LevelDbStorageTx)
func (tx *StorageTx) Add(atx db.Tx) error {
ldbtx := atx.(*StorageTx)
for _, v := range ldbtx.cache {
tx.cache.Put(v.K, v.V)
}
@@ -145,7 +145,7 @@ func (tx *LevelDbStorageTx) Add(atx db.Tx) error {
}
// Commit implements the method Commit of the interface db.Tx
func (tx *LevelDbStorageTx) Commit() error {
func (tx *StorageTx) Commit() error {
var batch leveldb.Batch
for _, v := range tx.cache {
batch.Put(v.K, v.V)
@@ -156,12 +156,12 @@ func (tx *LevelDbStorageTx) Commit() error {
}
// Close implements the method Close of the interface db.Tx
func (tx *LevelDbStorageTx) Close() {
func (tx *StorageTx) Close() {
tx.cache = nil
}
// Close implements the method Close of the interface db.Storage
func (l *LevelDbStorage) Close() {
func (l *Storage) Close() {
if err := l.ldb.Close(); err != nil {
panic(err)
}
@@ -169,12 +169,12 @@ func (l *LevelDbStorage) Close() {
}
// LevelDB is an extra method that returns the *leveldb.DB
func (l *LevelDbStorage) LevelDB() *leveldb.DB {
func (l *Storage) LevelDB() *leveldb.DB {
return l.ldb
}
// List implements the method List of the interface db.Storage
func (l *LevelDbStorage) List(limit int) ([]db.KV, error) {
func (l *Storage) List(limit int) ([]db.KV, error) {
ret := []db.KV{}
err := l.Iterate(func(key []byte, value []byte) (bool, error) {
ret = append(ret, db.KV{K: db.Clone(key), V: db.Clone(value)})

View File

@@ -51,7 +51,7 @@ func TestLevelDbInterface(t *testing.T) {
func TestMain(m *testing.M) {
result := m.Run()
for _, dir := range rmDirs {
os.RemoveAll(dir)
os.RemoveAll(dir) //nolint:errcheck,gosec
}
os.Exit(result)
}