@@ -0,0 +1,31 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Route 路由模型
|
||||
type Route 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:"-"`
|
||||
|
||||
Method string `gorm:"not null;size:10" json:"method"` // GET, POST, PUT, DELETE等
|
||||
Path string `gorm:"not null;size:255;uniqueIndex" json:"path"` // 路由路径
|
||||
Type string `gorm:"not null;size:50" json:"type"` // view, json, file, static, custom
|
||||
Handler string `gorm:"type:text" json:"handler"` // 处理函数或文件路径
|
||||
Description string `gorm:"size:500" json:"description"` // 路由描述
|
||||
IsActive bool `gorm:"default:true" json:"is_active"` // 是否启用
|
||||
Order int `gorm:"default:0" json:"order"` // 排序
|
||||
}
|
||||
|
||||
// TableName 指定表名(支持前缀)
|
||||
func (r Route) TableName() string {
|
||||
if tablePrefix != "" {
|
||||
return tablePrefix + "routes"
|
||||
}
|
||||
return "routes"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var tablePrefix = ""
|
||||
|
||||
// SetTablePrefix 设置表前缀(由 database 包调用)
|
||||
func SetTablePrefix(prefix string) {
|
||||
tablePrefix = prefix
|
||||
}
|
||||
|
||||
// User 用户模型
|
||||
type User 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:"-"`
|
||||
|
||||
Username string `gorm:"uniqueIndex;not null;size:50" json:"username"`
|
||||
Email string `gorm:"uniqueIndex;not null;size:100" json:"email"`
|
||||
Password string `gorm:"not null;size:255" json:"-"` // 不返回密码
|
||||
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
}
|
||||
|
||||
// TableName 指定表名(支持前缀)
|
||||
func (u User) TableName() string {
|
||||
if tablePrefix != "" {
|
||||
return tablePrefix + "users"
|
||||
}
|
||||
return "users"
|
||||
}
|
||||
Reference in New Issue
Block a user