diff options
author | xengineering <me@xengineering.eu> | 2024-05-04 20:07:35 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-05-04 20:07:35 +0200 |
commit | 7d8899e1d2bf45511d10670dd9a6ad386afb8da1 (patch) | |
tree | d46aa5c61bcb7db847e9da0c2700bfb06c14a55c /model | |
parent | 4c528668cc5d77c0859bdc237cef2e7c40b9b9d8 (diff) | |
download | ceres-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.
Diffstat (limited to 'model')
-rw-r--r-- | model/storage.go | 14 |
1 files changed, 9 insertions, 5 deletions
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) } |