Documentation ¶
Index ¶
- Variables
- func DbSetup(cfg config.DbConfig) (*gorm.DB, error)
- func EncryptPassword(pass *string) error
- func InitLogger(cfg zap.Config) (*zap.Logger, error)
- func TrimUsername(username *string)
- func Validate(username, password string) error
- func VerifyPassword(hash, pass string) error
- type Book
- type Record
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrPasswordRequired = errors.New("validate: password required")
ErrPasswordRequired occurs when the password field is left blank
var ErrUsernameRequired = errors.New("validate: username required")
ErrUsernameRequired occurs when the username field is left blank
Functions ¶
func EncryptPassword ¶
EncryptPassword encrypts the password
func InitLogger ¶
InitLogger initializes a logger to record all events and write to log files
func TrimUsername ¶
func TrimUsername(username *string)
TrimUsername removes whitespaces in the username
func VerifyPassword ¶
VerifyPassword verifies that the password matches the hash
Types ¶
type Book ¶
type Book struct { ID uint `json:"id"` Title string `json:"title" gorm:"NOT NULL"` Author string `json:"author"` Publisher string `json:"publisher"` ISBN string `json:"isbn"` }
Book is the basic object stored in the database
type Record ¶
type Record struct { ID uint `json:"id"` UserID uint `json:"user_id" gorm:"NOT NULL"` BookID uint `json:"book_id" gorm:"NOT NULL"` ReturnDate time.Time `json:"return_date" gorm:"NOT NULL"` ExtendTimes uint `json:"extend_times" gorm:"NOT NULL"` DeletedAt *time.Time `json:"real_return_date"` }
Record is stored when a user borrows a book from the library, and is soft deleted when the book is returned
type User ¶
type User struct { ID uint `json:"id"` Username string `json:"username" gorm:"NOT NULL; UNIQUE"` Password string `json:"password" gorm:"NOT NULL"` Level uint `json:"level" gorm:"NOT NULL"` }
User is a person who has access to the library Level indicates the user's privilege 0: Banned 1: User 2: Admin 3: Super Admin
func (*User) BeforeSave ¶
BeforeSave trims the username and encrypts the password before saving user data