summaryrefslogtreecommitdiff
path: root/persistence.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-20 19:19:19 +0200
committerxengineering <me@xengineering.eu>2023-05-20 19:19:45 +0200
commit6713c3cc833906802acf3ef89e5ac3dd7f69e128 (patch)
treed1bb8ff102f4aaeab623c69982098ccc434df81d /persistence.go
parent7b33036f9b4ea4ed91f60481a9eed30b8188167c (diff)
downloadlimox-6713c3cc833906802acf3ef89e5ac3dd7f69e128.tar
limox-6713c3cc833906802acf3ef89e5ac3dd7f69e128.tar.zst
limox-6713c3cc833906802acf3ef89e5ac3dd7f69e128.zip
Add persistence for last used JID
Diffstat (limited to 'persistence.go')
-rw-r--r--persistence.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/persistence.go b/persistence.go
new file mode 100644
index 0000000..5199fc5
--- /dev/null
+++ b/persistence.go
@@ -0,0 +1,55 @@
+package main
+
+import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+const (
+ RelDataPath = `/.config/limox`
+ RelJidPath = `/last_jid.txt`
+)
+
+func setLastJid(j string) {
+ data, err := assertDatadir()
+ if err != nil {
+ return
+ }
+
+ path := filepath.Join(data, RelJidPath)
+
+ _ = ioutil.WriteFile(path, []byte(j), 0644)
+}
+
+func getLastJid() string {
+ data, err := assertDatadir()
+ if err != nil {
+ return ""
+ }
+
+ path := filepath.Join(data, RelJidPath)
+
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ return ""
+ }
+
+ return string(content)
+}
+
+func assertDatadir() (string, error) {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "", err
+ }
+
+ path := filepath.Join(home, RelDataPath)
+
+ err = os.MkdirAll(path, 0755)
+ if err != nil {
+ return "", err
+ }
+
+ return path, nil
+}