Skip to content

Commit fdce574

Browse files
committed
add noop closer
1 parent ffe023c commit fdce574

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

storage/operation/badgerimpl/reader.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ import (
1010

1111
"github.com/onflow/flow-go/module/irrecoverable"
1212
"github.com/onflow/flow-go/storage"
13+
"github.com/onflow/flow-go/utils/noop"
1314
)
1415

1516
type dbReader struct {
1617
db *badger.DB
1718
}
1819

19-
type noopCloser struct{}
20-
21-
var _ io.Closer = (*noopCloser)(nil)
22-
23-
func (noopCloser) Close() error { return nil }
24-
2520
// Get gets the value for the given key. It returns ErrNotFound if the DB
2621
// does not contain the key.
2722
// other errors are exceptions
@@ -37,17 +32,17 @@ func (b dbReader) Get(key []byte) ([]byte, io.Closer, error) {
3732
item, err := tx.Get(key)
3833
if err != nil {
3934
if errors.Is(err, badger.ErrKeyNotFound) {
40-
return nil, noopCloser{}, storage.ErrNotFound
35+
return nil, noop.Closer{}, storage.ErrNotFound
4136
}
42-
return nil, noopCloser{}, irrecoverable.NewExceptionf("could not load data: %w", err)
37+
return nil, noop.Closer{}, irrecoverable.NewExceptionf("could not load data: %w", err)
4338
}
4439

4540
value, err := item.ValueCopy(nil)
4641
if err != nil {
47-
return nil, noopCloser{}, irrecoverable.NewExceptionf("could not load value: %w", err)
42+
return nil, noop.Closer{}, irrecoverable.NewExceptionf("could not load value: %w", err)
4843
}
4944

50-
return value, noopCloser{}, nil
45+
return value, noop.Closer{}, nil
5146
}
5247

5348
// NewIter returns a new Iterator for the given key prefix range [startPrefix, endPrefix], both inclusive.

storage/operation/pebbleimpl/reader.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/onflow/flow-go/module/irrecoverable"
1212
"github.com/onflow/flow-go/storage"
13+
"github.com/onflow/flow-go/utils/noop"
1314
)
1415

1516
type dbReader struct {
@@ -18,12 +19,6 @@ type dbReader struct {
1819

1920
var _ storage.Reader = (*dbReader)(nil)
2021

21-
type noopCloser struct{}
22-
23-
var _ io.Closer = (*noopCloser)(nil)
24-
25-
func (noopCloser) Close() error { return nil }
26-
2722
// Get gets the value for the given key. It returns ErrNotFound if the DB
2823
// does not contain the key.
2924
// other errors are exceptions
@@ -37,11 +32,11 @@ func (b dbReader) Get(key []byte) ([]byte, io.Closer, error) {
3732

3833
if err != nil {
3934
if errors.Is(err, pebble.ErrNotFound) {
40-
return nil, noopCloser{}, storage.ErrNotFound
35+
return nil, noop.Closer{}, storage.ErrNotFound
4136
}
4237

4338
// exception while checking for the key
44-
return nil, noopCloser{}, irrecoverable.NewExceptionf("could not load data: %w", err)
39+
return nil, noop.Closer{}, irrecoverable.NewExceptionf("could not load data: %w", err)
4540
}
4641

4742
return value, closer, nil

utils/noop/closer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package noop
2+
3+
import "io"
4+
5+
type Closer struct{}
6+
7+
var _ io.Closer = (*Closer)(nil)
8+
9+
func (Closer) Close() error { return nil }

0 commit comments

Comments
 (0)