refactor: storage interface
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"galaxy/model/client"
|
||||
"galaxy/model/order"
|
||||
"galaxy/model/report"
|
||||
"galaxy/util"
|
||||
)
|
||||
|
||||
type Storage interface {
|
||||
@@ -53,24 +50,3 @@ type UIStorage interface {
|
||||
// I/O or encoding error may occur, it that case callback func will be called with non-nil error.
|
||||
PutOrder(client.GameID, uint, order.Order, func(error))
|
||||
}
|
||||
|
||||
type storage struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func NewStorage(path string) (*storage, error) {
|
||||
if ok, err := util.PathExists(path, true); err != nil {
|
||||
return nil, fmt.Errorf("new storage: check path %q exists: %w", path, err)
|
||||
} else if !ok {
|
||||
return nil, fmt.Errorf("new storage: path %q does not exists", path)
|
||||
}
|
||||
if ok, err := util.Writable(path); err != nil {
|
||||
return nil, fmt.Errorf("new storage: check path %q writable: %w", path, err)
|
||||
} else if !ok {
|
||||
return nil, fmt.Errorf("new storage: path %q is not writable", path)
|
||||
}
|
||||
s := &storage{
|
||||
path: path,
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user