Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
func All() []interface{}
All returns all model structs for GORM AutoMigrate. Add new models here as they are created.
func OnlyTrashed ¶
OnlyTrashed returns a GORM scope that returns only soft-deleted records.
db.Scopes(models.OnlyTrashed).Find(&users)
Types ¶
type AuditLog ¶
type AuditLog struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null;default:0" json:"user_id"`
Action string `gorm:"size:50;not null;index" json:"action"`
ModelType string `gorm:"size:100;not null;index" json:"model_type"`
ModelID uint `gorm:"not null;index" json:"model_id"`
OldValues string `gorm:"type:text" json:"old_values,omitempty"`
NewValues string `gorm:"type:text" json:"new_values,omitempty"`
Metadata string `gorm:"type:text" json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
AuditLog records a single auditable action on a model.
type BaseModel ¶
type BaseModel struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
BaseModel provides common fields for all models. Embed this in your model structs to get ID, CreatedAt, UpdatedAt, and soft delete support via DeletedAt.
type Post ¶
type Post struct {
BaseModel
Title string `gorm:"size:255;not null" json:"title"`
Slug string `gorm:"size:255;uniqueIndex" json:"slug"`
Body string `gorm:"type:text" json:"body"`
UserID uint `gorm:"index;not null" json:"user_id"`
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}
Post represents a content entry authored by a user.
type User ¶
type User struct {
BaseModel
Name string `gorm:"size:100;not null" json:"name"`
Email string `gorm:"size:255;uniqueIndex;not null" json:"email"`
Password string `gorm:"size:255;not null" json:"-"`
Role string `gorm:"size:50;default:user" json:"role"`
Active bool `gorm:"default:true" json:"active"`
TOTPEnabled bool `gorm:"default:false" json:"totp_enabled"`
TOTPSecret string `gorm:"size:512" json:"-"`
TOTPVerifiedAt *time.Time `json:"totp_verified_at,omitempty"`
BackupCodesHash string `gorm:"type:text" json:"-"`
Posts []Post `gorm:"foreignKey:UserID" json:"posts,omitempty"`
}
User represents an application user.
Click to show internal directories.
Click to hide internal directories.