models

package
v0.0.0-...-59be28c Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: Apache-2.0 Imports: 7 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 returns a crypted password

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword verifies the password. if it matches, it will return nil or will return an error.

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;unique" json:"password"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Deleted   gorm.DeletedAt
}

User represents a user in the database

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) error

BeforeSave the hooks function that will be called before user struct create and update. It hash user password before save user info to database.

func (*User) DeleteAUser

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

DeleteAUser deletes a user from the database by user id.

func (*User) FindAllUsers

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

FindAllUsers find all first 100 users in database.

func (*User) FindUserByID

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

FindUserByID find the specific user by user id.

func (*User) Prepare

func (u *User) Prepare()

Prepare prepare user info and add created_at and updated_at

func (*User) SaveUser

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

SaveUser save user information to database.

func (*User) UpdateAUser

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

UpdateAUser update a user information in database by user id.

func (*User) Validate

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

Validate Validate user info.

Jump to

Keyboard shortcuts

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