models

package
v0.0.0-...-33f6d27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateEmail = errors.New("models: duplicate email")

Custom error for when a user attempts to sign up with an email address that is already being used.

View Source
var ErrInvalidCredentials = errors.New("models: invalid credentials")

Custom error for when a user attempts to login with an invalid email or invalid password.

View Source
var ErrNoRecord = errors.New("models: no matching record found")

Custom error for when an sql row query returns no matching records.

Functions

This section is empty.

Types

type Snippet

type Snippet struct {
	ID      int
	Title   string
	Content string
	Created time.Time
	Expires time.Time
}

Define a Snippet type to hold data for an individual Snippet.

type SnippetModel

type SnippetModel struct {
	DB *sql.DB
}

Define a SnippetModel type which wraps an sql.DB connection pool.

func (*SnippetModel) Get

func (m *SnippetModel) Get(id int) (*Snippet, error)

Define a function that will read and return a specified snippet based on its unique ID.

func (*SnippetModel) Insert

func (m *SnippetModel) Insert(title string, content string, expires int) (int, error)

Define a function that will insert a new snippet into the MYSQL database.

func (*SnippetModel) Latest

func (m *SnippetModel) Latest() ([]*Snippet, error)

Define a function that will return the 10 most recently created snippets.

type SnippetModelInterface

type SnippetModelInterface interface {
	Insert(title string, content string, expires int) (int, error)
	Get(id int) (*Snippet, error)
	Latest() ([]*Snippet, error)
}

type User

type User struct {
	ID             int
	Name           string
	Email          string
	HashedPassword string
	Created        time.Time
}

Define a User type to hold data for an individual User.

type UserModel

type UserModel struct {
	DB *sql.DB
}

Define a UserModel type which wraps an sql.DB connection pool.

func (*UserModel) Authenticate

func (m *UserModel) Authenticate(email, password string) (int, error)

func (*UserModel) Exists

func (m *UserModel) Exists(id int) (bool, error)

Function to check if a user with a specific ID exists in our database.

func (*UserModel) Insert

func (m *UserModel) Insert(name, email, password string) error

Define a function that will insert a new user into the MYSQL database.

type UserModelInterface

type UserModelInterface interface {
	Insert(name, email, password string) error
	Authenticate(email, password string) (int, error)
	Exists(id int) (bool, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL