Implement Read Only mode

This commit is contained in:
Las Zenow 2017-05-21 10:16:16 +00:00
parent 6464d92dd4
commit e1bd235785
19 changed files with 544 additions and 335 deletions

42
lib/storage/fs.go Normal file
View file

@ -0,0 +1,42 @@
package storage
import (
p "path"
"io"
"os"
)
type fsStore struct {
path string
}
func (st *fsStore) Create(id string, name string) (io.WriteCloser, error) {
path := idPath(st.path, id)
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
return nil, err
}
return os.Create(p.Join(path, name))
}
func (st *fsStore) Store(id string, file io.Reader, name string) (size int64, err error) {
dest, err := st.Create(id, name)
if err != nil {
return 0, err
}
defer dest.Close()
return io.Copy(dest, file)
}
func (st *fsStore) Get(id string, name string) (File, error) {
path := idPath(st.path, id)
return os.Open(p.Join(path, name))
}
func (st *fsStore) Delete(id string) error {
path := idPath(st.path, id)
return os.RemoveAll(path)
}