fileserver working
This commit is contained in:
@ -15,13 +15,13 @@ import (
|
||||
func NewInMem(c *config.Config, log *logrus.Logger) (Storage, error) {
|
||||
return &inMemStorage{
|
||||
stored: make(map[string][]byte),
|
||||
log: log,
|
||||
log: log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type inMemStorage struct {
|
||||
stored map[string][]byte
|
||||
log *logrus.Logger
|
||||
log *logrus.Logger
|
||||
}
|
||||
|
||||
func (s *inMemStorage) StoreFileAt(path string, data []byte) error {
|
||||
@ -41,7 +41,7 @@ func (s *inMemStorage) RetrieveFileFrom(path string) ([]byte, error) {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (s *inMemStorage)ListKeys() ([]string, error) {
|
||||
func (s *inMemStorage) ListKeys() ([]string, error) {
|
||||
keys := []string{}
|
||||
for k := range s.stored {
|
||||
keys = append(keys, k)
|
||||
|
||||
@ -28,7 +28,7 @@ func (s *localStorage) StoreFileAt(path string, data []byte) error {
|
||||
l := s.log.WithField("func", "StoreFileAt")
|
||||
l.Debugf("storing at path %s", path)
|
||||
components := strings.Split(path, "/")
|
||||
dir := strings.Join(components[0:len(components) - 1], "/")
|
||||
dir := strings.Join(components[0:len(components)-1], "/")
|
||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||
return fmt.Errorf("error writing file at %s: %s", path, err)
|
||||
}
|
||||
|
||||
@ -25,6 +25,6 @@ package storage
|
||||
type Storage interface {
|
||||
StoreFileAt(path string, data []byte) error
|
||||
RetrieveFileFrom(path string) ([]byte, error)
|
||||
ListKeys() ([]string, error)
|
||||
RemoveFileAt(path string) error
|
||||
ListKeys() ([]string, error)
|
||||
RemoveFileAt(path string) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user