db

package
v0.0.0-...-c6cd1c4 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func InitDB

func InitDB(dbPath string)

Types

type BaseModel

type BaseModel struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

type Short

type Short struct {
	BaseModel
	TargetURL  string     `gorm:"not null" json:"targetUrl"`
	VisitCount uint       `gorm:"default:0;not null" json:"visitCount,omitempty"`
	ExpiresAt  *time.Time `json:"expiresAt,omitempty"`
	MaxUses    *uint      `json:"maxUses,omitempty"`
	OwnerID    *uint      `json:"ownerId,omitempty"`
}

func GetShortByID

func GetShortByID(id uint) *Short

func (*Short) Create

func (s *Short) Create() error

func (*Short) IncrVisitCount

func (s *Short) IncrVisitCount() (uint, error)

Records a new visitor

func (*Short) IsExpired

func (s *Short) IsExpired() bool

Whether the short expiry has elapsed

func (*Short) IsUsable

func (s *Short) IsUsable() bool

Whether the short can be used (a redirect)

type User

type User struct {
	BaseModel
	Username       string  `gorm:"unique;not null"`
	HashedPassword []byte  `gorm:"not null" json:"-"`
	OwnedShorts    []Short `gorm:"foreignkey:OwnerID;references:id" json:"-"`
}

func GetUserByID

func GetUserByID(userID uint) *User

func GetUserByUsername

func GetUserByUsername(username string) *User

func (*User) IsPasswordMatch

func (u *User) IsPasswordMatch(plainPassword string) bool

Check if password matches the hashed stored one

func (*User) SetPassword

func (u *User) SetPassword(newPlainPassword string)

Set a new password (hashing it)

Jump to

Keyboard shortcuts

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