refactor: storage interface
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// fs implements Storage on filesystem
|
||||
package fs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"galaxy/util"
|
||||
)
|
||||
|
||||
type fs struct {
|
||||
rootPath string
|
||||
}
|
||||
|
||||
// NewStorage returns on-filesystem implementation of the "galaxy/storage.Storage" with root located at rootPath.
|
||||
// rootPath must me a directory and has write access to the current user. If initial checks failed, return nil and non-nil error.
|
||||
func NewFS(rootPath string) (*fs, error) {
|
||||
ok, err := util.Writable(rootPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, errors.New("user does not have write permissions to the storage root")
|
||||
}
|
||||
s := &fs{
|
||||
rootPath: rootPath,
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -11,9 +11,11 @@ import (
|
||||
|
||||
type Storage interface {
|
||||
UIStorage
|
||||
Exists(string) (bool, error)
|
||||
FileExists(string) (bool, error)
|
||||
ReadFile(string) ([]byte, error)
|
||||
WriteFile(string, []byte) error
|
||||
DeleteFile(string) error
|
||||
ListFiles() ([]string, error)
|
||||
}
|
||||
|
||||
// UIStorage manages Client's data local storing and retrieval.
|
||||
|
||||
Reference in New Issue
Block a user