package user import ( "database/sql" "math/rand" "time" "code.chrissexton.org/cws/happy/db" "github.com/speps/go-hashids" ) type User struct { db *db.Database ID int64 Email sql.NullString Verification int64 DateCreated sql.NullInt64 `db:"dateCreated"` LastLogin sql.NullInt64 `db:"lastLogin"` salt string str string } func New(db *db.Database, salt string, h *hashids.HashID) User { u := User{ db: db, salt: salt, DateCreated: sql.NullInt64{time.Now().Unix(), true}, LastLogin: sql.NullInt64{time.Now().Unix(), true}, Verification: rand.Int63(), } u.UpdateID(h) return u } func (u *User) UpdateID(h *hashids.HashID) error { idstr, err := h.EncodeInt64([]int64{u.ID}) if err != nil { return err } u.str = idstr return nil } func (u User) String() string { return u.str }