model

package
v0.0.0-...-c72a9d5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	ID        uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()"`
	CreatedAt time.Time `gorm:"default:now();not null"`
	UpdatedAt time.Time `gorm:"default:now();not null"`
}

Base contains common columns for all tables.

type User

type User struct {
	Base
	Username string `gorm:"not null;unique_index"`
	Password string `gorm:"not null"`
}

User resolves the user type.

func (*User) BeforeSave

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

func (*User) CheckPassword

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

Database will only save the hashed string, you should check it by util function.

if err := userModel.CheckPassword("password0"); err != nil { password error }

func (*User) SetPassword

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

What's bcrypt? https://en.wikipedia.org/wiki/Bcrypt Golang bcrypt doc: https://godoc.org/golang.org/x/crypto/bcrypt You can change the value in bcrypt.DefaultCost to adjust the security index.

err := userModel.SetPassword("password0")

Jump to

Keyboard shortcuts

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