write op working, sort of. encodes b64

This commit is contained in:
A.Unger
2020-01-31 09:36:17 +01:00
parent 31023b25b8
commit d02be70d52
2 changed files with 37 additions and 7 deletions
+19 -3
View File
@@ -2,15 +2,24 @@
package store
import (
"fmt"
"io/ioutil"
"log"
mstore "github.com/micro/go-micro/v2/store"
)
// Store interacts with the filesystem to manage account information
type Store struct{}
type Store struct {
mountPath string
}
// New returns a new file system store manager
// TODO add mountPath as an option argument
func New() Store {
return Store{}
return Store{
mountPath: "/var/tmp/ocis-store",
}
}
// Init implements the store interface
@@ -27,7 +36,14 @@ func (s *Store) Read(key string, opts ...mstore.ReadOption) ([]*mstore.Record, e
}
// Write implements the store interface
func (s *Store) Write(*mstore.Record) error {
func (s *Store) Write(rec *mstore.Record) error {
if rec.Key == "" {
return fmt.Errorf("%v", "key is empty")
}
if err := ioutil.WriteFile(s.mountPath+"/"+rec.Key, rec.Value, 0644); err != nil {
log.Panic(err)
}
return nil
}