some type stubs

This commit is contained in:
Bel LaPointe
2024-04-12 07:53:29 -06:00
parent 63d7454fb6
commit 8ee774240e
7 changed files with 250 additions and 0 deletions

37
storage.go Normal file
View 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
}