knowyt/server/src/application/loadUsers.go

30 lines
494 B
Go

package application
import (
"os"
"path"
"sirlab.de/go/knowyt/user"
)
func (app Application) loadUsers() error {
dirName := path.Join(app.config.DataDir, "users")
files, err := os.ReadDir(dirName)
if err != nil {
return err
}
app.mu.Lock()
defer app.mu.Unlock()
for _, file := range files {
fileName := path.Join(dirName, file.Name())
if usr, err := user.NewUserFromFile(fileName); err != nil {
return err
} else {
app.users[usr.GetId()] = usr
}
}
return nil
}