Additions to domain/ and workspace/ chron-note packages
This commit is contained in:
32
chron-note/internal/workspace/workspace.go
Normal file
32
chron-note/internal/workspace/workspace.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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())
|
||||
}
|
||||
Reference in New Issue
Block a user