39 lines
577 B
Go
39 lines
577 B
Go
|
package storage
|
||
|
|
||
|
type DB interface {
|
||
|
Store(Datapoint) error
|
||
|
Load(root []byte, key []byte, val interface{}) error
|
||
|
Delete(root []byte, key []byte) error
|
||
|
Close() error
|
||
|
}
|
||
|
|
||
|
type Datapoint interface {
|
||
|
Bucket() []byte
|
||
|
Key() []byte
|
||
|
Value() any
|
||
|
}
|
||
|
|
||
|
func RawData[T any](root []byte, key []byte, val T) Datapoint {
|
||
|
return &rawData[T]{
|
||
|
b: root,
|
||
|
k: key,
|
||
|
v: val,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
type rawData[T any] struct {
|
||
|
b []byte
|
||
|
k []byte
|
||
|
v T
|
||
|
}
|
||
|
|
||
|
func (d *rawData[T]) Bucket() []byte {
|
||
|
return d.b
|
||
|
}
|
||
|
func (d *rawData[T]) Key() []byte {
|
||
|
return d.k
|
||
|
}
|
||
|
func (d *rawData[T]) Value() any {
|
||
|
return d.v
|
||
|
}
|