summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-04 20:07:35 +0200
committerxengineering <me@xengineering.eu>2024-05-04 20:07:35 +0200
commit7d8899e1d2bf45511d10670dd9a6ad386afb8da1 (patch)
treed46aa5c61bcb7db847e9da0c2700bfb06c14a55c
parent4c528668cc5d77c0859bdc237cef2e7c40b9b9d8 (diff)
downloadceres-7d8899e1d2bf45511d10670dd9a6ad386afb8da1.tar
ceres-7d8899e1d2bf45511d10670dd9a6ad386afb8da1.tar.zst
ceres-7d8899e1d2bf45511d10670dd9a6ad386afb8da1.zip
model: Introduce type Storage
This new type definition will make it easier to handle the storage directory of Ceres and related functionality which can be implemented with methods.
-rw-r--r--main.go3
-rw-r--r--model/storage.go14
2 files changed, 11 insertions, 6 deletions
diff --git a/main.go b/main.go
index 7b65bf4..937fa8e 100644
--- a/main.go
+++ b/main.go
@@ -30,7 +30,8 @@ func main() {
os.Exit(0)
}
- model.InitStorage(config.StorageFilePath, gitDescribe)
+ storage := model.Storage{Path: config.StorageFilePath}
+ storage.Init(gitDescribe)
model.InitDatabase(config.StorageFilePath)
defer model.CloseDatabase()
diff --git a/model/storage.go b/model/storage.go
index bfebb6a..fcec125 100644
--- a/model/storage.go
+++ b/model/storage.go
@@ -6,21 +6,25 @@ import (
"path/filepath"
)
-func InitStorage(path string, version string) {
- err := os.Mkdir(path, 0750)
+type Storage struct {
+ Path string
+}
+
+func (s *Storage) Init(version string) {
+ err := os.Mkdir(s.Path, 0750)
if err != nil && !os.IsExist(err) {
log.Fatal(err)
}
- log.Printf("Created storage folder %s\n", path)
+ log.Printf("Created storage folder %s\n", s.Path)
if version != "" {
- vp := filepath.Join(path, "version.txt")
+ vp := filepath.Join(s.Path, "version.txt")
err = os.WriteFile(vp, []byte(version+"\n"), 0644)
if err != nil {
log.Fatal(err)
}
}
- log.Printf("Storage directory: %s\n", path)
+ log.Printf("Storage directory: %s\n", s.Path)
}