models

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidationFailed = errors.New("non valid data")
)

Functions

func GetAllModels

func GetAllModels() []any

GetAllModels returns a list of model instances for gorm migration. Any models added to this package that need to be migrated to the database should be included in this list.

Types

type User

type User struct {
	gorm.Model
	Email    string `gorm:"UNIQUE;NOT NULL" json:"email"`
	Username string `json:"username"`
	Password string `json:"password"`
}

func (*User) ComparePassword

func (u *User) ComparePassword(password string) (bool, error)

ComparePassword will evaluate the provided password witht the one stored against the user by hashing it first. If the passwords match, true will be returned (with a nil, error) otherswise, false will be returned.

If an error is returned, it means that the passwords weren't able to be compared, and so the result cannot be trusted.

func (*User) SetPassword

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

SetPassword will accept a string password and attempt to hash and salt it. Providing the hash is successful, the Password field of the User will be updated.

func (*User) Validate

func (u *User) Validate() ([]string, error)

Validate used to validate the data in this struct, needs to be ran before password hashing.

Jump to

Keyboard shortcuts

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