db

package
v0.0.0-...-d61641b Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateUser

func CreateUser(db *gorm.DB, username string) (error, string)

func DeleteExpiredKeys

func DeleteExpiredKeys(db *gorm.DB)

func DeleteKey

func DeleteKey(db *gorm.DB, key string)

func DeleteUser

func DeleteUser(db *gorm.DB, username string) bool

func GenerateKey

func GenerateKey(db *gorm.DB, user User) string

func GetApiKey

func GetApiKey(db *gorm.DB, username string) (string, bool)

func Init

func Init(lite bool) *gorm.DB

func OnlyAdmin

func OnlyAdmin(db *gorm.DB, key string) bool

func UpdateUserKey

func UpdateUserKey(db *gorm.DB, username string) string

func VerifyKey

func VerifyKey(db *gorm.DB, key string) bool

Types

type Key

type Key struct {
	gorm.Model
	Key     string
	UserID  uint
	Used    bool
	Expires time.Time
}

type User

type User struct {
	gorm.Model
	Username string `gorm:"unique;not null"`
	ApiKey   string
	Keys     []Key `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

func GetUserByApiKey

func GetUserByApiKey(db *gorm.DB, key string) User

Jump to

Keyboard shortcuts

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