Refactoring file storage driver to fsstorage

This commit is contained in:
Frederick F. Kautz IV
2014-12-08 14:25:57 -08:00
parent 8a5b8ac90f
commit 0cf80e075e
5 changed files with 14 additions and 23 deletions
+22
View File
@@ -0,0 +1,22 @@
package fsstorage
import (
"io/ioutil"
"os"
"path"
"path/filepath"
)
type FileSystemStorage struct {
RootDir string
}
func (storage FileSystemStorage) Get(objectPath string) ([]byte, error) {
return ioutil.ReadFile(path.Join(storage.RootDir, objectPath))
}
func (storage FileSystemStorage) Put(objectPath string, object []byte) error {
os.MkdirAll(filepath.Dir(path.Join(storage.RootDir, objectPath)), 0700)
return ioutil.WriteFile(path.Join(storage.RootDir, objectPath), object, 0600)
}