Documentation ¶
Index ¶
- Variables
- type Credentials
- type MySQLStore
- func (mss *MySQLStore) Delete(id int64) error
- func (mss *MySQLStore) GetByEmail(email string) (*User, error)
- func (mss *MySQLStore) GetByID(id int64) (*User, error)
- func (mss *MySQLStore) GetByUserName(username string) (*User, error)
- func (mss *MySQLStore) Insert(user *User) (*User, error)
- func (mss *MySQLStore) InsertLog(userID int64, ipAddr string) error
- func (mss *MySQLStore) Update(id int64, updates *Updates) (*User, error)
- type NewUser
- type Store
- type Updates
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrUserNotFound = errors.New("user not found")
ErrUserNotFound is returned when the user can't be found
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
Credentials represents user sign-in credentials
type MySQLStore ¶
type MySQLStore struct {
// contains filtered or unexported fields
}
MySQLStore represents a session store backed by MySQL
func NewMySQLStore ¶
func NewMySQLStore(DB *sql.DB) *MySQLStore
NewMySQLStore constructs a new MySQLStore
func (*MySQLStore) Delete ¶
func (mss *MySQLStore) Delete(id int64) error
Delete deletes the user from the MySQLStore with the given ID
func (*MySQLStore) GetByEmail ¶
func (mss *MySQLStore) GetByEmail(email string) (*User, error)
GetByEmail returns the user with the given email
func (*MySQLStore) GetByID ¶
func (mss *MySQLStore) GetByID(id int64) (*User, error)
GetByID with the given ID
func (*MySQLStore) GetByUserName ¶
func (mss *MySQLStore) GetByUserName(username string) (*User, error)
GetByUserName returns the user with the given username
func (*MySQLStore) Insert ¶
func (mss *MySQLStore) Insert(user *User) (*User, error)
Insert creates a new user in the MySQLStore and returns the created user
type NewUser ¶
type NewUser struct { Email string `json:"email"` Password string `json:"password"` PasswordConf string `json:"passwordConf"` UserName string `json:"userName"` }
NewUser represents a new user signing up for an account
type Store ¶
type Store interface { //GetByID returns the User with the given ID GetByID(id int64) (*User, error) //GetByEmail returns the User with the given email GetByEmail(email string) (*User, error) //GetByUserName returns the User with the given Username GetByUserName(username string) (*User, error) //Insert inserts the user into the database, and returns //the newly-inserted User, complete with the DBMS-assigned ID Insert(user *User) (*User, error) //Update applies UserUpdates to the given user ID //and returns the newly-updated user Update(id int64, updates *Updates) (*User, error) //Delete deletes the user with the given ID Delete(id int64) error //InsertLog inserts sign-in log to logs in the database InsertLog(userID int64, ipAddr string) error }
Store represents a store for Users
type User ¶
type User struct { ID int64 `json:"id"` Email string `json:"email"` PassHash []byte `json:"-"` //never JSON encoded/decoded UserName string `json:"userName"` }
User represents a user account in the database
func (*User) Authenticate ¶
Authenticate compares the plaintext password against the stored hash and returns an error if they don't match, or nil if they do
func (*User) SetPassword ¶
SetPassword hashes the password and stores it in the PassHash field