47 lines
2.0 KiB
Go
47 lines
2.0 KiB
Go
|
|
package entities
|
||
|
|
|
||
|
|
import "time"
|
||
|
|
|
||
|
|
// IPBlacklistEntry 管理端维护的 IP 黑名单
|
||
|
|
type IPBlacklistEntry struct {
|
||
|
|
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||
|
|
IP string `gorm:"type:varchar(64);not null;uniqueIndex" json:"ip"`
|
||
|
|
Reason string `gorm:"type:varchar(500);not null;default:''" json:"reason"`
|
||
|
|
Source string `gorm:"type:varchar(50);not null;default:'self'" json:"source"`
|
||
|
|
CreatedBy string `gorm:"type:varchar(36);not null;default:''" json:"created_by"`
|
||
|
|
CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"`
|
||
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||
|
|
DeletedAt *time.Time `gorm:"index" json:"-"` // 软删用手动字段,便于简单实现
|
||
|
|
IsActive bool `gorm:"not null;default:true;index" json:"is_active"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (IPBlacklistEntry) TableName() string {
|
||
|
|
return "ip_blacklist_entries"
|
||
|
|
}
|
||
|
|
|
||
|
|
// HitType 拦截类型
|
||
|
|
const (
|
||
|
|
HitTypeUserLogin = "user_login"
|
||
|
|
HitTypeUserJWT = "user_jwt"
|
||
|
|
HitTypeUserAPI = "user_api"
|
||
|
|
HitTypeIP = "ip"
|
||
|
|
)
|
||
|
|
|
||
|
|
// BlacklistHitRecord 黑名单拦截记录
|
||
|
|
type BlacklistHitRecord struct {
|
||
|
|
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||
|
|
HitType string `gorm:"type:varchar(32);not null;index:idx_hit_type_created,priority:1" json:"hit_type"`
|
||
|
|
UserID string `gorm:"type:varchar(36);index" json:"user_id,omitempty"`
|
||
|
|
Phone string `gorm:"type:varchar(20);index" json:"phone,omitempty"`
|
||
|
|
IP string `gorm:"type:varchar(64);index" json:"ip,omitempty"`
|
||
|
|
Path string `gorm:"type:varchar(255);not null;default:''" json:"path"`
|
||
|
|
Method string `gorm:"type:varchar(16);not null;default:''" json:"method"`
|
||
|
|
Reason string `gorm:"type:varchar(500);not null;default:''" json:"reason"`
|
||
|
|
UserAgent string `gorm:"type:varchar(512);not null;default:''" json:"user_agent"`
|
||
|
|
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_hit_type_created,priority:2;index" json:"created_at"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (BlacklistHitRecord) TableName() string {
|
||
|
|
return "blacklist_hit_records"
|
||
|
|
}
|