diff options
author | xengineering <me@xengineering.eu> | 2023-12-27 12:03:53 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-12-27 12:18:14 +0100 |
commit | 318f00c5d496296e45311ea81e8b80d9bd03b1d5 (patch) | |
tree | bf7c58978b7cdb5d54d30b4ecbad94c0efbdbc15 | |
parent | ea54de7d32e6b576ccfb430e7e57811b7c4587fe (diff) | |
download | ceres-318f00c5d496296e45311ea81e8b80d9bd03b1d5.tar ceres-318f00c5d496296e45311ea81e8b80d9bd03b1d5.tar.zst ceres-318f00c5d496296e45311ea81e8b80d9bd03b1d5.zip |
model: Implement temporary storage directory
This temporary directory is provided to store the user data for the
Ceres recipe server during development and testing.
-rw-r--r-- | main.go | 10 | ||||
-rw-r--r-- | model/storage.go | 28 |
2 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,10 @@ +package main + +import ( + "xengineering.eu/ceres/model" +) + +func main() { + model.InitStorage() + defer model.RemoveStorage() +} diff --git a/model/storage.go b/model/storage.go new file mode 100644 index 0000000..39539d4 --- /dev/null +++ b/model/storage.go @@ -0,0 +1,28 @@ +package model + +import ( + "log" + "os" +) + +var storage string + +func InitStorage() { + var err error + + storage, err = os.MkdirTemp("", "ceres-") + if err != nil { + log.Fatal(err) + } + + log.Printf("Storage directory: %s\n", storage) +} + +func RemoveStorage() { + var err error = os.RemoveAll(storage) + if err != nil { + log.Printf("Failed to remove temporary storage folder: %v\n", err) + } else { + log.Println("Removed temporary storage folder") + } +} |