Files
galaxy-game/pkg/storage/fs/fs.go
T
2026-03-13 17:05:37 +02:00

31 lines
928 B
Go

// fs implements galaxy/storage.Storage with filesystem
package fs
import (
"fmt"
"galaxy/util"
)
type fsStorage struct {
path string
}
// NewFS 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 NewStorage(path string) (*fsStorage, 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 := &fsStorage{
path: path,
}
return s, nil
}