tooling
This commit is contained in:
@@ -24,7 +24,6 @@ func (s Service) Set(c context.Context, req *proto.Record, res *proto.Record) er
|
||||
|
||||
settingsJSON, err := json.Marshal(req.Payload)
|
||||
if err != nil {
|
||||
// TODO log the error
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,24 +4,34 @@ package store
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
mstore "github.com/micro/go-micro/v2/store"
|
||||
olog "github.com/owncloud/ocis-pkg/log"
|
||||
)
|
||||
|
||||
// DefaultPath assumes UNIX
|
||||
var DefaultPath string = "/var/tmp/ocis-store"
|
||||
// Logger is a global logger
|
||||
var Logger olog.Logger
|
||||
|
||||
// Store interacts with the filesystem to manage account information
|
||||
type Store struct {
|
||||
logger olog.Logger
|
||||
mountPath string
|
||||
}
|
||||
|
||||
// New returns a new file system store manager
|
||||
// TODO add mountPath as a flag
|
||||
// TODO add mountPath as a flag. Accept a *config argument
|
||||
func New() Store {
|
||||
// default to the current working directory if not configured
|
||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
if err != nil {
|
||||
// TODO log error
|
||||
// TODO deal with this
|
||||
}
|
||||
return Store{
|
||||
mountPath: DefaultPath,
|
||||
mountPath: dir,
|
||||
logger: olog.NewLogger(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,16 +52,17 @@ func (s *Store) Read(key string, opts ...mstore.ReadOption) ([]*mstore.Record, e
|
||||
func (s *Store) Write(rec *mstore.Record) error {
|
||||
path := filepath.Join(s.mountPath, rec.Key)
|
||||
|
||||
if filepath.IsAbs(path) {
|
||||
// TODO WARN, storage is relative to the service directory
|
||||
}
|
||||
|
||||
if len(rec.Key) < 1 {
|
||||
// TODO log error: empty key
|
||||
return fmt.Errorf("%v", "key is empty")
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(path, rec.Value, 0644)
|
||||
if err := ioutil.WriteFile(path, rec.Value, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.logger.Info().Msgf("%v bytes written to %v", len(rec.Value), path)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete implements the store interface
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// String gets defined by the build system.
|
||||
String = "0.0.0"
|
||||
|
||||
// Date indicates the build date.
|
||||
Date = "00000000"
|
||||
)
|
||||
|
||||
// Compiled returns the compile time of this service.
|
||||
func Compiled() time.Time {
|
||||
t, _ := time.Parse("20060102", Date)
|
||||
return t
|
||||
}
|
||||
Reference in New Issue
Block a user