Semaphore/db/User.go

27 lines
800 B
Go
Raw Normal View History

2017-02-23 06:12:16 +01:00
package db
2016-01-05 00:32:53 +01:00
import (
"time"
)
//User is the model for an entity which has access to the API
2016-01-05 00:32:53 +01:00
type User struct {
2016-03-19 00:23:03 +01:00
ID int `db:"id" json:"id"`
2016-01-05 00:32:53 +01:00
Created time.Time `db:"created" json:"created"`
Username string `db:"username" json:"username" binding:"required"`
Name string `db:"name" json:"name" binding:"required"`
Email string `db:"email" json:"email" binding:"required"`
2016-04-02 14:40:07 +02:00
Password string `db:"password" json:"-"`
Admin bool `db:"admin" json:"admin"`
External bool `db:"external" json:"external"`
Alert bool `db:"alert" json:"alert"`
2016-01-05 00:32:53 +01:00
}
2016-03-18 23:03:28 +01:00
//FetchUser retrieves a user from the database by ID
2016-03-18 23:03:28 +01:00
func FetchUser(userID int) (*User, error) {
var user User
2020-11-28 22:49:44 +01:00
err := Sql.SelectOne(&user, "select * from `user` where id=?", userID)
2016-03-18 23:03:28 +01:00
return &user, err
}