knowyt/server/src/application/loadUsers.go

30 lines
492 B
Go
Raw Normal View History

2021-08-04 22:12:28 +00:00
package application
import (
"os"
"path"
"sirlab.de/go/knyt/user"
)
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
}