users

package
v0.0.0-...-52ed2a8 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound is returned when the user does not
	// exists or was not found given the search parameters.
	ErrUserNotFound = errors.New("user not found")
	// ErrInvalidUser is returned when the user given is not valid
	ErrInvalidUser = errors.New("invalid user")
)

Functions

func Create

func Create(db *sqlx.DB, u *User, pw string) error

Create will create a user

func Delete

func Delete(db *sqlx.DB, u User) error

Delete a user

Types

type User

type User struct {
	ID        int       `db:"id" json:"id"`
	Name      string    `db:"name" json:"name"`
	Email     string    `db:"email" json:"email,omitempty"`
	IsAdmin   bool      `db:"is_admin" json:"is_admin"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	Hash      []byte    `db:"hash" json:"-"`
	// contains filtered or unexported fields
}

User is a user model

func GetUserByID

func GetUserByID(db *sqlx.DB, id interface{}) (*User, error)

GetUserByID will get a user from the database by id

func GetUserByName

func GetUserByName(db *sqlx.DB, name string) (*User, error)

GetUserByName will query the database for a user with a specific name

func (*User) Delete

func (u *User) Delete() (err error)

Delete will delete the user

func (*User) PasswordOK

func (u *User) PasswordOK(pw string) (ok bool)

PasswordOK check a password string against the stored password hash and returns false if the password is incorrect.

func (*User) Save

func (u *User) Save() error

Save will save the user to the database

func (*User) SetDB

func (u *User) SetDB(db *sqlx.DB)

SetDB allows callers to set the internal database field on the user struct

Jump to

Keyboard shortcuts

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