feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers

This commit is contained in:
2026-04-02 11:19:50 +08:00
parent e59a77bc49
commit dcc1f186f8
298 changed files with 62603 additions and 0 deletions

45
internal/domain/device.go Normal file
View File

@@ -0,0 +1,45 @@
package domain
import "time"
// DeviceType 设备类型
type DeviceType int
const (
DeviceTypeUnknown DeviceType = iota
DeviceTypeWeb
DeviceTypeMobile
DeviceTypeDesktop
)
// DeviceStatus 设备状态
type DeviceStatus int
const (
DeviceStatusInactive DeviceStatus = 0
DeviceStatusActive DeviceStatus = 1
)
// Device 设备模型
type Device struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
UserID int64 `gorm:"not null;index" json:"user_id"`
DeviceID string `gorm:"type:varchar(100);uniqueIndex;not null" json:"device_id"`
DeviceName string `gorm:"type:varchar(100)" json:"device_name"`
DeviceType DeviceType `gorm:"type:int;default:0" json:"device_type"`
DeviceOS string `gorm:"type:varchar(50)" json:"device_os"`
DeviceBrowser string `gorm:"type:varchar(50)" json:"device_browser"`
IP string `gorm:"type:varchar(50)" json:"ip"`
Location string `gorm:"type:varchar(100)" json:"location"`
IsTrusted bool `gorm:"default:false" json:"is_trusted"` // 是否信任该设备
TrustExpiresAt *time.Time `gorm:"type:datetime" json:"trust_expires_at"` // 信任过期时间
Status DeviceStatus `gorm:"type:int;default:1" json:"status"`
LastActiveTime time.Time `json:"last_active_time"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}
// TableName 指定表名
func (Device) TableName() string {
return "devices"
}