X-Git-Url: https://code.octet-stream.net/broadcaster/blobdiff_plain/7b615b3c71825b5b229b78509a16db37e1d3f38d..6f8503e889dc1f45eddd987ee44e6338712de4fe:/server/database.go?ds=inline diff --git a/server/database.go b/server/database.go index 1312208..06e5968 100644 --- a/server/database.go +++ b/server/database.go @@ -79,6 +79,15 @@ func (d *Database) GetUser(username string) (User, error) { return user, nil } +func (d *Database) GetUserById(id int) (User, error) { + var user User + err := d.sqldb.QueryRow("SELECT id, username, password_hash, is_admin FROM users WHERE id = ?", id).Scan(&user.Id, &user.Username, &user.PasswordHash, &user.IsAdmin) + if err != nil { + return User{}, errors.New("no user with that id") + } + return user, nil +} + func (d *Database) GetUsers() []User { ret := make([]User, 0) rows, err := d.sqldb.Query("SELECT id, username, password_hash, is_admin FROM users ORDER BY username ASC")