database

package
v0.0.0-...-234d524 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateUser

func AuthenticateUser(ctx context.Context, db *gorm.DB) bool

func AuthorizeUser

func AuthorizeUser(ctx context.Context, db *gorm.DB, fn AuthorizationFunction) bool

func HashPassword

func HashPassword(password string) (string, error)

func Migrate

func Migrate(db *gorm.DB) error

func NewDatabase

func NewDatabase() (*gorm.DB, error)

Types

type AuthorizationFunction

type AuthorizationFunction func(UserOut) bool

type User

type User struct {
	gorm.Model
	ID        uint      `gorm:"primaryKey;autoIncrement" json:"id,omitempty"`
	Username  string    `gorm:"not null;unique" json:"username"`
	Fullname  string    `gorm:"not null" json:"fullname"`
	Email     string    `gorm:"not null;unique" json:"email"`
	Password  string    `gorm:"not null"  json:"password"`
	IsAdmin   bool      `gorm:"default:false" json:"isAdmin"`
	CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt,omitempty"`
	UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updatedAt,omitempty"`
}

func (*User) Out

func (u *User) Out() UserOut

type UserIn

type UserIn struct {
	Username string `json:"username"`
	Fullname string `json:"fullname"`
	Email    string `json:"email"`
	Password string `json:"password"`
	IsAdmin  bool   `json:"isAdmin"`
}

type UserOut

type UserOut struct {
	ID        uint      `json:"id"`
	Username  string    `json:"username"`
	Fullname  string    `json:"fullname"`
	Email     string    `json:"email"`
	IsAdmin   bool      `json:"isAdmin"`
	CreatedAt time.Time `json:"createdAt,omitempty"`
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
}

func GetAuthUser

func GetAuthUser(ctx context.Context, db *gorm.DB) (UserOut, error)

func UserArrayOut

func UserArrayOut(models []User) []UserOut

Jump to

Keyboard shortcuts

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