generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyspace.go
35 lines (27 loc) · 1.07 KB
/
keyspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package kv
import "context"
// A RangeFunc is a function used to range over the key/value pairs in a
// [Keyspace].
//
// If err is non-nil, ranging stops and err is propagated up the stack.
// Otherwise, if ok is false, ranging stops without any error being propagated.
type RangeFunc[K, V any] func(ctx context.Context, k K, v V) (ok bool, err error)
// A Keyspace is an isolated collection of key/value pairs.
type Keyspace[K, V any] interface {
// Name returns the name of the keyspace.
Name() string
// Get returns the value associated with k.
//
// If the key does not exist v is the zero-value of V.
Get(ctx context.Context, k K) (v V, err error)
// Has returns true if k is present in the keyspace.
Has(ctx context.Context, k K) (ok bool, err error)
// Set associates a value with k.
//
// If v is the zero-value of V (or equivalent), the key is deleted.
Set(ctx context.Context, k K, v V) error
// Range invokes fn for each key in the keyspace in an undefined order.
Range(ctx context.Context, fn RangeFunc[K, V]) error
// Close closes the keyspace.
Close() error
}