Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotFound is a custom error we return when a resource we are looking for is not present in the db ErrNotFound = errors.New("models: resource not found") // ErrIDInvalid is a custom error we return when the id of user we want to delete is invalid ErrIDInvalid = errors.New("models: ID provided was invalid") // ErrPasswordIncorrect is a custom error we return when the user enters an invalid password in login page ErrPasswordIncorrect = errors.New("models: incorrect password provided") // ErrEmailRequired is a custom error we return when the email address is not provided when creating a user ErrEmailRequired = errors.New("models: email address is required") // ErrEmailInvalid is a custom error we return when the email address provided doesn't match requirements ErrEmailInvalid = errors.New("models: email address is not valid") // ErrEmailTaken is a custom error we return when create or update is called with an email address that is already in use ErrEmailTaken = errors.New("models: email address is already taken") // ErrPasswordTooShort is a custom error we return when the password set at account creation is too short ErrPasswordTooShort = errors.New("models: password must be atleast 8 characters long") // ErrPasswordRequired is a custom error we return when user tries to create an account without setting a password ErrPasswordRequired = errors.New("models: password is required") // ErrRememberRequired is a custom error we return when create or update is attempted without a user remember token hash ErrRememberRequired = errors.New("models: remember token is required") // ErrRememberTooShort is a custom error we return when the remember token is not 32 bytes long ErrRememberTooShort = errors.New("models: remember token must be atleast 32 bytes") )
Functions ¶
This section is empty.
Types ¶
type User ¶
type User struct { gorm.Model Name string Email string `gorm:"not null;unique_index"` Password string `gorm:"-"` PasswordHash string `gorm:"not null"` Remember string `gorm:"-"` RememberHash string `gorm:"not null;unique_index"` }
User is the database model for our customer
type UserDB ¶
type UserDB interface { // Methods for querying for single users ByID(id uint) (*User, error) ByEmail(email string) (*User, error) ByRemember(token string) (*User, error) // Methods for altering users Create(user *User) error Update(user *User) error Delete(id uint) error // Used to close a DB connection Close() error // Migration helpers AutoMigrate() error DestructiveReset() error }
UserDB is used to interact with the users database
type UserService ¶
UserService is a set of methods used to manipulate and work with the user model
func NewUserService ¶
func NewUserService(connectionInfo string) (UserService, error)
NewUserService is an abstraction layer providing us a connection with the db
Click to show internal directories.
Click to hide internal directories.