aboutsummaryrefslogtreecommitdiff
path: root/persistence
diff options
context:
space:
mode:
Diffstat (limited to 'persistence')
-rw-r--r--persistence/sessions.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/persistence/sessions.go b/persistence/sessions.go
index 36fac52..ab46823 100644
--- a/persistence/sessions.go
+++ b/persistence/sessions.go
@@ -6,6 +6,7 @@ import (
"dev.narayana.im/narayana/telegabber/yamldb"
+ log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
@@ -44,6 +45,10 @@ func LoadSessions(path string) (SessionsYamlDB, error) {
return sessionDB, nil
}
+func emptySessionsMap(dataPtr *SessionsMap) {
+ dataPtr.Sessions = make(map[string]Session)
+}
+
func initYamlDB(path string, dataPtr *SessionsMap) (SessionsYamlDB, error) {
file, err := ioutil.ReadFile(path)
if err == nil {
@@ -51,9 +56,14 @@ func initYamlDB(path string, dataPtr *SessionsMap) (SessionsYamlDB, error) {
if err != nil {
return SessionsYamlDB{}, errors.Wrap(err, "YamlDB is corrupted")
}
+
+ if dataPtr.Sessions == nil {
+ emptySessionsMap(dataPtr)
+ }
+ log.Debugf("Unmarshalled YAML: %#v", *dataPtr)
} else {
// DB file does not exist, create an empty DB
- dataPtr.Sessions = make(map[string]Session)
+ emptySessionsMap(dataPtr)
}
return SessionsYamlDB{