models

package
v0.0.0-...-edc8a76 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a resource cannot be found in the database.
	ErrNotFound = errors.New("models: resource not found")
	// ErrInvalidID is returned when an invalid ID is provided to a method (e.g. Delete).
	ErrInvalidID = errors.New("models: ID must be > 0")

	ErrInvalidPassword = errors.New("models: incorrect password provided")
)

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"`
}

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

func NewUserService

func NewUserService(connectionInfo string) (*UserService, error)

func (*UserService) Authenticate

func (us *UserService) Authenticate(email, password string) (*User, error)

Authenticate can be used to authenticate a user with the provided email address and password.

func (*UserService) AutoMigrate

func (us *UserService) AutoMigrate() error

AutoMigrate will attempt to automatically migrate the Users table.

func (*UserService) ByEmail

func (us *UserService) ByEmail(email string) (*User, error)

ByEmail will look up a user with the provided email address.

func (*UserService) ByID

func (us *UserService) ByID(id uint) (*User, error)

ByID will look up a user with the provided id.

func (*UserService) Close

func (us *UserService) Close() error

Close closes the UserService database connection.

func (*UserService) Create

func (us *UserService) Create(user *User) error

Create creates the provided user and will backfill data (e.g. ID, CreatedAt, UpdatedAt, DeletedAt).

func (*UserService) Delete

func (us *UserService) Delete(id uint) error

Delete will delete the user with the provided id.

func (*UserService) DestructiveReset

func (us *UserService) DestructiveReset() error

DestructiveReset drops the User table and rebuilds it.

func (*UserService) Update

func (us *UserService) Update(user *User) error

Update will update the provided user with all of the data in the provided user object.

Jump to

Keyboard shortcuts

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