33 lines
494 B
Go
33 lines
494 B
Go
package repo
|
|
|
|
import (
|
|
"encoding"
|
|
|
|
"github.com/iliadenisov/galaxy/pkg/repo/fs"
|
|
)
|
|
|
|
type Storage interface {
|
|
Lock() (func() error, error)
|
|
Write(string, encoding.BinaryMarshaler) error
|
|
Read(string, encoding.BinaryUnmarshaler) error
|
|
}
|
|
|
|
type repo struct {
|
|
s Storage
|
|
}
|
|
|
|
func NewRepo(s Storage) (*repo, error) {
|
|
r := &repo{
|
|
s: s,
|
|
}
|
|
return r, nil
|
|
}
|
|
|
|
func NewFileRepo(path string) (*repo, error) {
|
|
s, err := fs.NewFileStorage(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return NewRepo(s)
|
|
}
|