From 17149f2c58c1a1157372f7eeab1c5b9eaa51069b Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 2 Oct 2022 14:39:55 -0400 Subject: [PATCH] Add file store --- pkg/config/config.go | 3 ++- pkg/server/server.go | 5 ++++- pkg/storage/storage.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 pkg/storage/storage.go diff --git a/pkg/config/config.go b/pkg/config/config.go index 7a6f946..2fb19ff 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -12,7 +12,8 @@ import ( ) type Config struct { - Server *server.Config `yaml:"server"` + DataDir *string `yaml:"data_dir,omitempty"` + Server *server.Config `yaml:"server"` } const ( diff --git a/pkg/server/server.go b/pkg/server/server.go index fe7b266..aa5d478 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -33,7 +33,10 @@ func (s *Server) installRoutes() { } func New(cfg *config.Config) (s *Server, err error) { - b := blas.New(cfg) + b, err := blas.New(cfg) + if err != nil { + return nil, err + } s = &Server{ Blas: b, diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go new file mode 100644 index 0000000..7e2cd13 --- /dev/null +++ b/pkg/storage/storage.go @@ -0,0 +1,28 @@ +package storage + +import ( + "io/fs" +) + +type Data interface { +} + +type Item struct { + Version int `json:"version"` + MinorVersion *int `json:"minor_version,omitempty"` + Key string `json:"key"` + Data Data `json:"data"` +} + +type Store struct { + fs.FS +} + +func Open(dir fs.FS) (*Store, error) { + stor, err := fs.Sub(dir, ".storage") + if err != nil { + return nil, err + } + + return &Store{stor}, nil +}