package database import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) const ( SubjectProgramming = "Programming" SubjectPentesting = "Pentesting" ) // Base contains common columns for all tables type Base struct { ID uuid.UUID `gorm:"primaryKey;autoIncrement:false"` CreatedAt time.Time UpdatedAt time.Time DeletedAt time.Time } // BeforeCreate will set Base struct before every insert func (base *Base) BeforeCreate(tx *gorm.DB) error { // uuid.New() creates a new random UUID or panics. base.ID = uuid.New() // generate timestamps var t time.Time = time.Now() base.CreatedAt, base.UpdatedAt = t, t return nil } // AfterUpdate will update the Base struct after every update func (base *Base) AfterUpdate(tx *gorm.DB) error { // update timestamps base.UpdatedAt = time.Now() return nil } type Post struct { Base Title string `gorm:"type:varchar(256);"` Intro string HtmlPath string `gorm:"type:varchar(256);uniqueindex;"` Subject string `gorm:"type:varchar(256);"` MainImage string `gorm:"type:varchar(256);"` Body string `sql:"-"` } type SidebarLink struct { Base Name string Link string }