data

package
v0.0.0-...-1b61129 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Models

type Models struct {
	User User
}

Models is the type for this package. Note that any model that is included as a member in this type is available to us throughout the application, anywhere that the app variable is used, provided that the model is also added in the New function.

func New

func New(dbPool *sql.DB) Models

New is the function used to create an instance of the data package. It returns the type Model, which embeds all the types we want to be available to our application.

type User

type User struct {
	ID         int       `json:"id"`
	Email      string    `json:"email"`
	GivenName  string    `json:"given_name,omitempty"`
	FamilyName string    `json:"family_name,omitempty"`
	Password   string    `json:"-"`
	Active     int       `json:"active"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

User is the structure which holds one user from the database. Modified the basic human identifiers to follow OpenID Connect namings

func (*User) Delete

func (u *User) Delete() error

Delete deletes one user from the database, by User.ID

func (*User) DeleteByID

func (u *User) DeleteByID(id int) error

DeleteByID deletes one user from the database, by ID

func (*User) GetAll

func (u *User) GetAll() ([]*User, error)

GetAll returns a slice of all users, sorted by family name

func (*User) GetByEmail

func (u *User) GetByEmail(email string) (*User, error)

GetByEmail returns one user by email

func (*User) GetOne

func (u *User) GetOne(id int) (*User, error)

GetOne returns one user by id

func (*User) Insert

func (u *User) Insert(user User) (int, error)

Insert inserts a new user into the database, and returns the ID of the newly inserted row

func (*User) PasswordMatches

func (u *User) PasswordMatches(plainText string) (bool, error)

PasswordMatches uses Go's bcrypt package to compare a user supplied password with the hash we have stored for a given user in the database. If the password and hash match, we return true; otherwise, we return false.

func (*User) ResetPassword

func (u *User) ResetPassword(password string) error

ResetPassword is the method we will use to change a user's password.

func (*User) Update

func (u *User) Update() error

Update updates one user in the database, using the information stored in the receiver u

Jump to

Keyboard shortcuts

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