diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-04 18:55:15 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-04 18:55:15 +0300 |
commit | 354a4acd19d5376477275588d3e170df6a688697 (patch) | |
tree | 380de3d9b7fe1868760068f2a63717c5e3d5633b /persistence | |
parent | 3ce5081800ebf1ca92d32f1a051db4671b5105d3 (diff) |
Fix session restoring
Diffstat (limited to 'persistence')
-rw-r--r-- | persistence/sessions.go | 13 |
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", |