Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoRecord = errors.New("models: no matching record found") // Add a new ErrInvalidCredentials error. We'll use this later if a user // tries to login with an incorrect email address or password. ErrInvalidCredentials = errors.New("models: invalid credentials") // Add a new ErrDuplicateEmail error. We'll use this later if a user // tries to signup with an email address that's already in use. ErrDuplicateEmail = errors.New("models: duplicate email") )
Functions ¶
This section is empty.
Types ¶
type Snippet ¶
Define a Snippet type to hold the data for an individual snippet. Notice how the fields of the struct correspond to the fields in our MySQL snippets table?
type SnippetModel ¶
Define a SnippetModel type which wraps a sql.DB connection pool.
func (*SnippetModel) Get ¶
func (m *SnippetModel) Get(id int) (Snippet, error)
This will return a specific snippet based on its id.
func (*SnippetModel) Latest ¶
func (m *SnippetModel) Latest() ([]Snippet, error)
This will return the 10 most recently created snippets.
type SnippetModelInterface ¶
type User ¶
Define a new User struct. Notice how the field names and types align with the columns in the database "users" table?
type UserModel ¶
Define a new UserModel struct which wraps a database connection pool.
func (*UserModel) Authenticate ¶
We'll use the Authenticate method to verify whether a user exists with the provided email address and password. This will return the relevant user ID if they do.