- 48 个 Go 文件所有注释(行注释/块注释/行尾注释,含 _test.go)翻译为中文 - 保留技术标识符:SECURITY_TODO(n)、unsafe-inline、sqlite/mysql、路由参数等 - 代码、字符串字面量、日志消息保持英文原文,零逻辑改动 - go build/vet 通过,go test -count=1 ./... 全绿
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 文章状态常量。
|
|
const (
|
|
ArticleDraft = 0 // 草稿
|
|
ArticlePublished = 1 // 已发布
|
|
ArticleArchived = 2 // 已归档
|
|
)
|
|
|
|
// Article 表示一篇博客文章。
|
|
type Article struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:idx_slug_deleted_at" json:"deleted_at"`
|
|
AuthorID uint `gorm:"not null;index" json:"author_id"`
|
|
Title string `gorm:"not null;size:255" json:"title"`
|
|
Summary string `gorm:"size:512" json:"summary"`
|
|
Content string `gorm:"type:text;not null" json:"content"`
|
|
Cover string `gorm:"size:512" json:"cover"`
|
|
Status int `gorm:"default:0;index" json:"status"`
|
|
IsTop bool `gorm:"default:false" json:"is_top"`
|
|
ViewCount int `gorm:"default:0" json:"view_count"`
|
|
Slug string `gorm:"uniqueIndex:idx_slug_deleted_at;size:255" json:"slug"`
|
|
PublishedAt *time.Time `gorm:"index" json:"published_at"`
|
|
Author User `gorm:"foreignKey:AuthorID" json:"-"`
|
|
Tags []Tag `gorm:"many2many:article_tags;" json:"tags"`
|
|
}
|
|
|
|
// TableName 覆盖 GORM 默认的表名。
|
|
func (Article) TableName() string {
|
|
return "articles"
|
|
}
|