some type stubs
This commit is contained in:
37
storage.go
Normal file
37
storage.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotFound = errors.New("not found")
|
||||
)
|
||||
|
||||
type Storage struct {
|
||||
driver Driver
|
||||
}
|
||||
|
||||
func NewTestStorage() Storage {
|
||||
return Storage{driver: NewTestDB()}
|
||||
}
|
||||
|
||||
func NewStorage(driver Driver) Storage {
|
||||
return Storage{driver: driver}
|
||||
}
|
||||
|
||||
func (s Storage) Upsert(ctx context.Context, m Message) error {
|
||||
return s.driver.Set(ctx, "storage", m.ID, m.Serialize())
|
||||
}
|
||||
|
||||
func (s Storage) Get(ctx context.Context, id string) (Message, error) {
|
||||
b, err := s.driver.Get(ctx, "storage", id)
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
if b == nil {
|
||||
return Message{}, ErrNotFound
|
||||
}
|
||||
return MustDeserialize(b), nil
|
||||
}
|
||||
Reference in New Issue
Block a user