models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPassword

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

HashPassword encrypts a password so it can be stored safely

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword decrypts and checks if a hashed password is the same as the given string

Types

type ChatroomDB

type ChatroomDB struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

ChatroomDB allows the app to neatly interface with GORM

func NewChatroomDB

func NewChatroomDB(db *sql.DB, logger *log.Entry) (*ChatroomDB, error)

NewChatroomDB instantiates a new ChatroomDB object

func (*ChatroomDB) Migrate

func (c *ChatroomDB) Migrate() error

Migrate runs the migrations on the GORM models

type User

type User struct {
	gorm.Model
	ID       string `gorm:"primary_key"`
	Username string `gorm:"not null;unique" json:"username"`
	Email    string `gorm:"not null;unique" json:"email"`
	Password string `gorm:"not null;" json:"password"`
}

User is an entity that can log in our system

func (*User) BeforeSave

func (u *User) BeforeSave() error

BeforeSave is a GORM hook that encrypts the password before saving it

func (*User) Init

func (u *User) Init()

Init prepares a user object to be saved

func (*User) Validate

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

Validate checks if a user model is correctly formed

Jump to

Keyboard shortcuts

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