diff options
Diffstat (limited to 'user.go')
-rw-r--r-- | user.go | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -8,14 +8,20 @@ type User struct { isAdmin bool } -func createUser(db *sqlite3.Conn, name string, isAdmin bool) { +func createUser(db *sqlite3.Conn, name string, isAdmin bool) (User, error) { + + user := getUserForName(db, name) //Check if a user with this name already exists - if (getUserForName(db, name).id == 0) { + if (user.id == 0) { args := sqlite3.NamedArgs{"$a": name, "$b": isAdmin} sql := "INSERT INTO users (name, admin) VALUES ($a, $b)" - db.Exec(sql, args) + err := db.Exec(sql, args) + + return User{id:db.LastInsertId(), name:name, isAdmin:isAdmin}, err + } else { + return user, nil } } |