models

package
v0.0.0-...-ff63446 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ListOfTables = []any{
	User{},
	Session{},
}

Functions

This section is empty.

Types

type BadaasServerInfo

type BadaasServerInfo struct {
	Status  string `json:"status"`
	Version string `json:"version"`
}

Describe the current BADAAS instance

type BaseModel

type BaseModel struct {
	ID        uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4()"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Base Model for gorm

Every model intended to be saved in the database must embed this BaseModel reference: https://gorm.io/docs/models.html#gorm-Model

type Session

type Session struct {
	BaseModel
	UserID    uuid.UUID `gorm:"not null"`
	ExpiresAt time.Time `gorm:"not null"`
}

Represent a user session

func (*Session) CanBeRolled

func (session *Session) CanBeRolled(rollInterval time.Duration) bool

Return true if the session is expired in less than an hour

func (*Session) IsExpired

func (session *Session) IsExpired() bool

Return true is expired

func (Session) TableName

func (Session) TableName() string

Return the pluralized table name

Satisfie the Tabler interface

type Tabler

type Tabler interface {
	// pluralized name
	TableName() string
}

The interface "type" need to implement to be considered models

type User

type User struct {
	BaseModel
	Username string `gorm:"not null"`
	Email    string `gorm:"unique;not null"`

	// password hash
	Password []byte `gorm:"not null"`
}

Represents a user

func (User) TableName

func (User) TableName() string

Return the pluralized table name

Satisfie the Tabler interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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