models

package
v0.0.0-...-6a72777 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(password string) ([]byte, error)

Hash generator

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword func to check if passwords match

Types

type User

type User struct {
	ID        uint32    `gorm:"primary_key;auto_increment" json:"id"`
	Nickname  string    `gorm:"size:255;not null;unique" json:"nickname"`
	Email     string    `gorm:"size:100;not null;unique" json:"email"`
	Password  string    `gorm:"size:100;not null;" json:"password"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

User model definition

func (*User) BeforeSave

func (u *User) BeforeSave() error

BeforeSave func to generate user pass hash and set it

func (*User) DeleteAUser

func (u *User) DeleteAUser(db *gorm.DB, uid uint32) (int64, error)

DeleteAUser func to delete a given user by id

func (*User) FindAllUsers

func (u *User) FindAllUsers(db *gorm.DB) ([]UserReturn, error)

FindAllUsers func to query all the users in the db

func (*User) FindUserByID

func (u *User) FindUserByID(db *gorm.DB, uid uint32) (UserReturn, error)

FindUserByID func to get a particular by ID

func (*User) Prepare

func (u *User) Prepare()

Prepare func to set other user field(except pass)

func (*User) SaveUser

func (u *User) SaveUser(db *gorm.DB) (*User, error)

SaveUser func to save user to db

func (*User) UpdateAUser

func (u *User) UpdateAUser(db *gorm.DB, uid uint32) (*User, error)

UpdateAUser func to update a given user by id

func (*User) Validate

func (u *User) Validate(action string) error

Validate func to check user datails before saving or login

type UserReturn

type UserReturn struct {
	ID       uint32
	Nickname string
	Email    string
}

UserReturn return struct

Jump to

Keyboard shortcuts

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