Commit 8f77a3b

mo khan <mo@mokhan.ca>
2024-06-05 22:45:30
Create directory if it does not exist
1 parent 620b3a0
Changed files (1)
pkg/db/client.go
@@ -1,12 +1,22 @@
 package db
 
+import (
+	"os"
+	"path/filepath"
+
+	"github.com/xlgmokha/x/pkg/x"
+)
+
 type Storage[T any] struct {
 	dir string
 }
 
 func New[T any](dir string) *Storage[T] {
+	fullPath := x.Must(filepath.Abs(dir))
+	x.Check(os.MkdirAll(fullPath, 0700))
+
 	return &Storage[T]{
-		dir: dir,
+		dir: fullPath,
 	}
 }