2021-08-04 22:12:28 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
2022-03-03 07:40:14 +00:00
|
|
|
"sirlab.de/go/knowyt/user"
|
2021-08-04 22:12:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (app Application) loadUsers() error {
|
|
|
|
dirName := path.Join(app.config.DataDir, "users")
|
|
|
|
files, err := os.ReadDir(dirName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-09 08:36:19 +00:00
|
|
|
|
|
|
|
app.mu.Lock()
|
|
|
|
defer app.mu.Unlock()
|
|
|
|
|
2021-08-04 22:12:28 +00:00
|
|
|
for _, file := range files {
|
|
|
|
fileName := path.Join(dirName, file.Name())
|
2021-08-09 08:22:32 +00:00
|
|
|
if usr, err := user.NewUserFromFile(fileName); err != nil {
|
2021-08-04 22:12:28 +00:00
|
|
|
return err
|
|
|
|
} else {
|
2021-08-04 22:40:31 +00:00
|
|
|
app.users[usr.GetId()] = usr
|
2021-08-04 22:12:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|