Files
chron/chron-note/internal/workspace/workspace.go

33 lines
574 B
Go

package workspace
import (
"fmt"
"os"
"path/filepath"
"git.michelsen.id/phill/chron/chron-note/internal/domain"
)
type Workspace struct {
Root string
Dir string
}
func Open(root string) (*Workspace, error) {
root = filepath.Clean(root)
dir := filepath.Join(root, ".chron", "workspace")
if err := os.MkdirAll(dir, 0o755); err != nil {
return nil, fmt.Errorf("mkdir workspace dir: %w", err)
}
return &Workspace{
Root: root,
Dir: dir,
}, nil
}
func (ws *Workspace) ObjectPath(id domain.ObjectID) string {
return filepath.Join(ws.Dir, id.String())
}