From 354a4acd19d5376477275588d3e170df6a688697 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Wed, 4 Dec 2019 17:55:15 +0200 Subject: Fix session restoring --- persistence/sessions.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'persistence') 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", -- cgit v1.2.3