summaryrefslogtreecommitdiff
path: root/user.go
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-07-21 11:51:34 +0100
committerJoe Robinson <joe@mumsnet.com>2014-07-21 11:51:34 +0100
commit5b1d414ba23937e7fe1eba74547a7acf33e9c5a6 (patch)
treef8fd9b1c9860201a10408c82855ac4a4f8cde1ce /user.go
parentc4c2aee4aa4ce2b726f14cb8f91f20801d2e6784 (diff)
Added some error checking
Diffstat (limited to 'user.go')
-rw-r--r--user.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/user.go b/user.go
index b686f74..f2a5afd 100644
--- a/user.go
+++ b/user.go
@@ -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
}
}