feat(*): go 后端项目脚手架

This commit is contained in:
2025-11-15 18:20:30 +08:00
commit 5bb025c1aa
39 changed files with 2459 additions and 0 deletions

16
internal/model/cateage.go Normal file
View File

@@ -0,0 +1,16 @@
package model
import (
"time"
)
type Cateage struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `gorm:"index" json:"-"`
AnchorId string `gorm:"size:100;not null;unique" json:"anchor_id"`
Name string `gorm:"size:100;not null;unique" json:"name"`
Sites []Site `gorm:"foreignKey:CateageID" json:"sites"` // 方便获取分类下所有网站
}

16
internal/model/model.go Normal file
View File

@@ -0,0 +1,16 @@
package model
import (
"github.com/zhilv666/navsite/pkg/db"
"github.com/zhilv666/navsite/pkg/logger"
"go.uber.org/zap"
)
func Init() {
err := db.GetDB().AutoMigrate(
new(User), new(Cateage), new(Site),
)
if err != nil {
logger.Error("database migrate error", zap.Stack("migrate"))
}
}

18
internal/model/site.go Normal file
View File

@@ -0,0 +1,18 @@
package model
import "time"
type Site struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `gorm:"index" json:"-"`
Name string `gorm:"size:100;not null;unique" json:"name"`
Describe string `gorm:"size:100" json:"describe"`
CateageID uint `gorm:"not null;index" json:"cateage_id"`
Cateage Cateage `gorm:"foreignKey:CateageID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"cateage"` // 外键关联
Url string `gorm:"size:500;not null" json:"url"`
Cors bool `gorm:"default:false" json:"cors"`
Icon string `gorm:"size:500;default:'https://cos.kmux.cn/md/20251115174627218.png'" json:"icon"`
}

23
internal/model/user.go Normal file
View File

@@ -0,0 +1,23 @@
package model
import (
"time"
)
type User struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
DeletedAt *time.Time `gorm:"index" json:"-"`
Username string `gorm:"uniqueIndex;size:50;not null" json:"username"` // 邮箱注册
Email string `gorm:"uniqueIndex;size:100;not null" json:"email"`
Password string `json:"-" gorm:"size:100;not null"` // SHA1 密码
Salt string `json:"-" gorm:"size:32;not null"` // 密码盐
IsAdmin bool `json:"is_admin"` // true = 管理员
Disabled bool `json:"disabled" gorm:"default:false"` // 禁用标志
SsoID string `json:"sso_id" gorm:"size:100;unique"` // OAuth2 唯一标识
Verified bool `json:"verified" gorm:"default:false"` // 是否通过邮箱验证/管理员审核
VerifyAt *time.Time `json:"verify_at,omitempty"` // 验证时间
Points int `json:"points" gorm:"default:0"` // 积分
}