aboutsummaryrefslogtreecommitdiff
path: root/persistence/sessions.go
diff options
context:
space:
mode:
Diffstat (limited to 'persistence/sessions.go')
-rw-r--r--persistence/sessions.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/persistence/sessions.go b/persistence/sessions.go
index ab46823..d15c4f3 100644
--- a/persistence/sessions.go
+++ b/persistence/sessions.go
@@ -26,7 +26,7 @@ type Session struct {
Login string `yaml:":login"`
}
-var sessionDB SessionsYamlDB
+var sessionDB *SessionsYamlDB
// SessionMarshaller implementation for YamlDB
func SessionMarshaller() ([]byte, error) {
@@ -34,10 +34,11 @@ func SessionMarshaller() ([]byte, error) {
}
// LoadSessions restores TDlib sessions from the previous run
-func LoadSessions(path string) (SessionsYamlDB, error) {
+func LoadSessions(path string) (*SessionsYamlDB, error) {
var sessionData SessionsMap
+ var err error
- sessionDB, err := initYamlDB(path, &sessionData)
+ sessionDB, err = initYamlDB(path, &sessionData)
if err != nil {
return sessionDB, errors.Wrap(err, "Sessions restore error")
}
@@ -49,12 +50,12 @@ func emptySessionsMap(dataPtr *SessionsMap) {
dataPtr.Sessions = make(map[string]Session)
}
-func initYamlDB(path string, dataPtr *SessionsMap) (SessionsYamlDB, error) {
+func initYamlDB(path string, dataPtr *SessionsMap) (*SessionsYamlDB, error) {
file, err := ioutil.ReadFile(path)
if err == nil {
err = yaml.Unmarshal(file, dataPtr)
if err != nil {
- return SessionsYamlDB{}, errors.Wrap(err, "YamlDB is corrupted")
+ return nil, errors.Wrap(err, "YamlDB is corrupted")
}
if dataPtr.Sessions == nil {
@@ -66,7 +67,7 @@ func initYamlDB(path string, dataPtr *SessionsMap) (SessionsYamlDB, error) {
emptySessionsMap(dataPtr)
}
- return SessionsYamlDB{
+ return &SessionsYamlDB{
YamlDB: yamldb.YamlDB{
Path: path,
PathNew: path + ".new",