model

package
v4.0.0-alpha.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentDiagnosticTaskStatusPending    = "pending"
	AgentDiagnosticTaskStatusDispatched = "dispatched"
	AgentDiagnosticTaskStatusCompleted  = "completed"
	AgentDiagnosticTaskStatusFailed     = "failed"
)
View Source
const (
	ForwardNodeTypeRelay = "relay" // 中转节点
	ForwardNodeTypeExit  = "exit"  // 落地节点
)

ForwardNodeType 节点类型

View Source
const (
	ForwardNodeStatusOffline = 0
	ForwardNodeStatusOnline  = 1
)

ForwardNodeStatus 节点状态

View Source
const (
	ForwardAgentBridgeTaskStatusPending    = "pending"
	ForwardAgentBridgeTaskStatusDispatched = "dispatched"
	ForwardAgentBridgeTaskStatusCompleted  = "completed"
	ForwardAgentBridgeTaskStatusFailed     = "failed"
)
View Source
const (
	ForwardCleanAgentStatusRevoked = -1
	ForwardCleanAgentStatusOffline = 0
	ForwardCleanAgentStatusOnline  = 1
)
View Source
const (
	LatencyTargetTypeForward     = "forward"      // forward -> remote_addr 目标
	LatencyTargetTypeTunnelNode  = "tunnel_node"  // 隧道中继/出口节点端点
	LatencyTargetTypeForwardNode = "forward_node" // ForwardNode 管理端点 (HealthCheck)
	LatencyTargetTypeNode        = "node"         // 常规代理节点 v2_node (V2bX 注册)
)

LatencyTargetType 延迟探测目标类型

View Source
const (
	ForwardTunnelStatusDisabled = 0
	ForwardTunnelStatusActive   = 1
)
View Source
const (
	ForwardStatusPaused = 0
	ForwardStatusActive = 1
	ForwardStatusError  = -1
)
View Source
const (
	ForwardUserTunnelStatusDisabled = 0
	ForwardUserTunnelStatusActive   = 1
)
View Source
const (
	ForwardRuntimeBackendGost            = "gost"
	ForwardRuntimeBackendNftablesAnsible = "nftables_ansible"
	ForwardRuntimeBackendIptablesAnsible = "iptables_ansible"
	ForwardRuntimeBackendCleanAgent      = "clean_agent"
)
View Source
const (
	// These status values are also used by Forward.RuntimeStatus as the latest runtime sync state.
	ForwardRuntimeJobStatusPending = 0
	ForwardRuntimeJobStatusRunning = 1
	ForwardRuntimeJobStatusSuccess = 2
	ForwardRuntimeJobStatusFailed  = 3
)
View Source
const (
	ForwardRuntimeJobActionCreate = "create"
	ForwardRuntimeJobActionUpdate = "update"
	ForwardRuntimeJobActionDelete = "delete"
	ForwardRuntimeJobActionPause  = "pause"
	ForwardRuntimeJobActionResume = "resume"
	ForwardRuntimeJobActionSync   = "sync"
)
View Source
const (
	MFAMethodTOTP   = "totp"   // TOTP验证器
	MFAMethodSMS    = "sms"    // 短信验证
	MFAMethodEmail  = "email"  // 邮箱验证
	MFAMethodBackup = "backup" // 备用码
)

MFAMethod MFA方式

View Source
const (
	// 用户相关
	EventUserRegister      = "user.register"       // 用户注册
	EventUserLogin         = "user.login"          // 用户登录 (新设备)
	EventUserPasswordReset = "user.password_reset" // 密码重置
	EventUserMFAEnabled    = "user.mfa_enabled"    // MFA启用

	// 账户状态
	EventUserExpire           = "user.expire"            // 用户到期 (提前通知)
	EventUserExpired          = "user.expired"           // 用户已到期
	EventUserTrafficLow       = "user.traffic_low"       // 流量不足
	EventUserTrafficExhausted = "user.traffic_exhausted" // 流量耗尽
	EventUserBanned           = "user.banned"            // 用户被封禁

	// 订单支付
	EventOrderCreated  = "order.created"  // 订单创建
	EventOrderPaid     = "order.paid"     // 订单支付成功
	EventOrderExpired  = "order.expired"  // 订单过期
	EventOrderRefunded = "order.refunded" // 订单退款

	// 工单系统
	EventTicketCreated = "ticket.created" // 工单创建
	EventTicketReplied = "ticket.replied" // 工单回复
	EventTicketClosed  = "ticket.closed"  // 工单关闭

	// 节点相关
	EventNodeOffline  = "node.offline"   // 节点离线
	EventNodeOnline   = "node.online"    // 节点上线
	EventNodeHighLoad = "node.high_load" // 节点高负载

	// 系统通知
	EventSystemBroadcast   = "system.broadcast"   // 系统广播
	EventSystemMaintenance = "system.maintenance" // 维护通知
)

NotificationEvent 通知事件

View Source
const (
	PaymentMethodCrypto = "crypto" // 虚拟货币支付 (X402)
	PaymentMethodFiat   = "fiat"   // 法币支付 (Stripe/PayPal等)
)

PaymentMethod 支付方式枚举

View Source
const (
	// 虚拟货币支付提供商
	PaymentProviderX402 = "x402" // X402 协议

	// 法币支付提供商
	PaymentProviderStripe    = "stripe"
	PaymentProviderPayPal    = "paypal"
	PaymentProviderAlipay    = "alipay"
	PaymentProviderWechatPay = "wechat_pay"
)

PaymentProvider 支付提供商枚举

View Source
const (
	PaymentStatusPending   = 0 // 待支付
	PaymentStatusPaid      = 1 // 已支付
	PaymentStatusCancelled = 2 // 已取消
	PaymentStatusRefunded  = 3 // 已退款
	PaymentStatusExpired   = 4 // 已过期
)

PaymentStatus 支付状态枚举

View Source
const (
	PaymentGatewayAlipay = "alipay" // 支付宝
	PaymentGatewayWechat = "wechat" // 微信支付
	PaymentGatewayEPay   = "epay"   // EPay通用支付
	PaymentGatewayUSDT   = "usdt"   // USDT加密货币 (TRC20/ERC20)
	PaymentGatewayStripe = "stripe" // Stripe信用卡
	PaymentGatewayPayPal = "paypal" // PayPal
	PaymentGatewayX402   = "x402"   // X402虚拟货币协议
)

PaymentGatewayType 支付网关类型

View Source
const (
	SpeedLimitStatusDisabled = 0
	SpeedLimitStatusActive   = 1
)
View Source
const (
	NotificationTypeExpire  = "expire"  // 到期通知
	NotificationTypeTraffic = "traffic" // 流量不足
	NotificationTypeTicket  = "ticket"  // 工单回复
	NotificationTypeSystem  = "system"  // 系统通知
	NotificationTypePayment = "payment" // 支付通知
	NotificationTypeNode    = "node"    // 节点通知
)

NotificationType 通知类型

Variables

This section is empty.

Functions

func KernelModels

func KernelModels() []any

Types

type AccessGroup

type AccessGroup struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	ScopeID     string    `gorm:"size:64;not null;uniqueIndex:ux_access_group_scope_name" json:"scope_id"`
	Name        string    `gorm:"size:120;not null;uniqueIndex:ux_access_group_scope_name" json:"name"`
	Description string    `gorm:"type:text" json:"description"`
	Enabled     bool      `gorm:"not null" json:"enabled"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func (AccessGroup) TableName

func (AccessGroup) TableName() string

type AccessGroupPlan

type AccessGroupPlan struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	GroupID   uint      `gorm:"not null;uniqueIndex:ux_access_group_plan" json:"group_id"`
	PlanID    uint      `gorm:"not null;uniqueIndex:ux_access_group_plan;index" json:"plan_id"`
	CreatedAt time.Time `json:"created_at"`
}

func (AccessGroupPlan) TableName

func (AccessGroupPlan) TableName() string

type AccessGroupUser

type AccessGroupUser struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	GroupID   uint      `gorm:"not null;uniqueIndex:ux_access_group_user" json:"group_id"`
	UserID    uint      `gorm:"not null;uniqueIndex:ux_access_group_user;index" json:"user_id"`
	CreatedAt time.Time `json:"created_at"`
}

func (AccessGroupUser) TableName

func (AccessGroupUser) TableName() string

type AdminCreateUserRequest

type AdminCreateUserRequest struct {
	Email          string `json:"email" binding:"required,email"`
	Password       string `json:"password" binding:"required,min=6"`
	IsAdmin        int    `json:"is_admin"`
	FlowResetTime  int64  `json:"flowResetTime"`
	GroupID        *uint  `json:"group_id"`
	TransferEnable *int64 `json:"transfer_enable"`
	SpeedLimit     *int64 `json:"speed_limit"`
	DeviceLimit    *int   `json:"device_limit"`
}

AdminCreateUserRequest 管理员创建用户请求

type AgentDiagnosticTask

type AgentDiagnosticTask struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	TaskID     string    `gorm:"size:80;uniqueIndex" json:"task_id"`
	NodeID     uint      `gorm:"index" json:"node_id"`
	Action     string    `gorm:"size:40" json:"action"`
	Params     string    `gorm:"type:text" json:"params,omitempty"`
	Status     string    `gorm:"size:20;index" json:"status"`
	Success    bool      `json:"success"`
	Output     string    `gorm:"type:text" json:"output,omitempty"`
	Error      string    `gorm:"type:text" json:"error,omitempty"`
	DurationMS int64     `json:"duration_ms"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"timestamp"`
}

AgentDiagnosticTask 持久化白名单诊断任务(NodeX Agent 终端功能),使任务结果在 面板进程重启后仍可查询,不再依赖 AgentHandler.taskResults 这张纯内存表。 JSON 字段沿用原 AgentTaskStatus 的 snake_case 命名,保持与前端 Agent.vue 的契约不变。

func (AgentDiagnosticTask) TableName

func (AgentDiagnosticTask) TableName() string

type AlipayConfig

type AlipayConfig struct {
	AppID      string `json:"app_id"`      // 应用ID
	PrivateKey string `json:"private_key"` // 应用私钥
	PublicKey  string `json:"public_key"`  // 支付宝公钥
	NotifyURL  string `json:"notify_url"`  // 异步通知地址
	ReturnURL  string `json:"return_url"`  // 同步跳转地址
	Sandbox    bool   `json:"sandbox"`     // 沙箱模式
}

AlipayConfig 支付宝配置

type AuditLog

type AuditLog struct {
	ID           uint   `gorm:"primaryKey" json:"id"`
	UserID       *uint  `gorm:"index" json:"user_id"`
	Email        string `gorm:"size:255" json:"email"`
	Method       string `gorm:"size:10" json:"method"`        // HTTP method
	Path         string `gorm:"size:500" json:"path"`         // Request path
	Module       string `gorm:"size:100;index" json:"module"` // Extracted module from path
	Action       string `gorm:"size:50;index" json:"action"`  // create/update/delete/etc.
	IP           string `gorm:"size:45" json:"ip"`            // Client IP
	UserAgent    string `gorm:"size:500" json:"user_agent"`
	RequestID    string `gorm:"size:64" json:"request_id"`      // Correlation ID
	RequestBody  string `gorm:"type:text" json:"request_body"`  // Request body (truncated)
	StatusCode   int    `json:"status_code"`                    // HTTP response status
	DurationMS   int64  `json:"duration_ms"`                    // Request duration in milliseconds
	ErrorMessage string `gorm:"type:text" json:"error_message"` // Error if status >= 400

	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

AuditLog records detailed audit trail for admin operations. Designed for compliance and security review.

func (AuditLog) TableName

func (AuditLog) TableName() string

TableName specifies the table name for audit logs.

type AuthorizedKey

type AuthorizedKey struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"size:100" json:"name"`           // 密钥名称/备注
	Key       string    `gorm:"size:64;uniqueIndex" json:"key"` // 授权密钥
	KeyHash   string    `gorm:"size:64" json:"-"`               // 密钥哈希 (不返回给前端)
	Used      int       `gorm:"default:0" json:"used"`          // 已注册节点数量
	ExpireAt  *int64    `json:"expire_at"`                      // 过期时间 (null=永不过期)
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

AuthorizedKey 授权密钥 (用于节点自动注册)

func (AuthorizedKey) TableName

func (AuthorizedKey) TableName() string

type BackupConfig

type BackupConfig struct {
	ID             uint   `gorm:"primaryKey" json:"id"`
	Enabled        bool   `gorm:"default:false" json:"enabled"`
	AutoBackup     bool   `gorm:"default:false" json:"auto_backup"`
	Schedule       string `gorm:"size:50" json:"schedule"`         // cron表达式
	RetentionDays  int    `gorm:"default:7" json:"retention_days"` // 保留天数
	BackupDatabase bool   `gorm:"default:true" json:"backup_database"`
	BackupFiles    bool   `gorm:"default:false" json:"backup_files"`
	StorageType    string `gorm:"size:20;default:local" json:"storage_type"` // local/s3/ftp
	StoragePath    string `gorm:"size:255" json:"storage_path"`
	S3Bucket       string `gorm:"size:100" json:"s3_bucket"`
	S3Region       string `gorm:"size:50" json:"s3_region"`
	S3Endpoint     string `gorm:"size:255" json:"s3_endpoint"`
	S3AccessKey    string `gorm:"size:100" json:"s3_access_key"`
	S3SecretKey    string `gorm:"size:100" json:"s3_secret_key"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

BackupConfig 备份配置

func (BackupConfig) TableName

func (BackupConfig) TableName() string

TableName 指定表名

type BackupRecord

type BackupRecord struct {
	ID        uint   `gorm:"primaryKey" json:"id"`
	Name      string `gorm:"size:100" json:"name"`
	Type      string `gorm:"size:20" json:"type"`       // full/database/files
	Size      int64  `json:"size"`                      // 文件大小(字节)
	Path      string `gorm:"size:255" json:"path"`      // 存储路径
	Status    int    `gorm:"default:0" json:"status"`   // 0=进行中 1=成功 2=失败
	Error     string `gorm:"type:text" json:"error"`    // 错误信息
	Auto      bool   `gorm:"default:false" json:"auto"` // 是否自动备份
	CreatedBy *uint  `json:"created_by"`                // 创建者ID

	CompletedAt *time.Time `json:"completed_at"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

BackupRecord 备份记录

func (BackupRecord) TableName

func (BackupRecord) TableName() string

TableName 指定表名

type BaseServer

type BaseServer struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	GroupID     string    `gorm:"type:varchar(255)" json:"group_id"` // JSON array of group IDs
	RouteID     string    `gorm:"type:varchar(255)" json:"route_id"` // JSON array of route IDs
	ParentID    *uint     `json:"parent_id"`
	Tags        *string   `gorm:"type:varchar(255)" json:"tags"`
	Name        string    `gorm:"size:255" json:"name"`
	Rate        float64   `gorm:"default:1" json:"rate"`
	Host        string    `gorm:"size:255" json:"host"`
	Port        int       `json:"port"`
	ServerPort  int       `json:"server_port"`
	TLS         int       `gorm:"default:0" json:"tls"` // 0: None, 1: TLS, 2: Reality
	TLSSettings *string   `gorm:"type:text" json:"tls_settings"`
	Show        int       `gorm:"default:0" json:"show"`
	Sort        *int      `json:"sort"`
	LastCheckAt *int64    `json:"last_check_at"` // 最后检查时间
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

BaseServer 服务器基础模型

func (*BaseServer) GetGroupIDs

func (s *BaseServer) GetGroupIDs() []uint

GetGroupIDs 获取分组ID列表

func (*BaseServer) GetRouteIDs

func (s *BaseServer) GetRouteIDs() []uint

GetRouteIDs 获取路由ID列表

type CommissionRecord

type CommissionRecord struct {
	ID         uint    `gorm:"primaryKey" json:"id"`
	UserID     uint    `gorm:"index" json:"user_id"`      // 获得佣金的用户
	OrderID    uint    `gorm:"index" json:"order_id"`     // 关联订单
	FromUserID uint    `gorm:"index" json:"from_user_id"` // 被邀请用户
	Amount     float64 `json:"amount"`                    // 佣金金额
	Type       int     `json:"type"`                      // 1=订单佣金 2=充值佣金 3=系统赠送
	Status     int     `gorm:"default:0" json:"status"`   // 0=待确认 1=已到账 2=已提现 3=已取消
	Remark     string  `gorm:"size:255" json:"remark"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

CommissionRecord 佣金记录

func (CommissionRecord) TableName

func (CommissionRecord) TableName() string

TableName 指定表名

type CommissionWithdraw

type CommissionWithdraw struct {
	ID      uint    `gorm:"primaryKey" json:"id"`
	UserID  uint    `gorm:"index" json:"user_id"`
	Amount  float64 `json:"amount"`                  // 提现金额
	Method  string  `gorm:"size:20" json:"method"`   // alipay/wechat/bank
	Account string  `gorm:"size:100" json:"account"` // 收款账号
	Name    string  `gorm:"size:50" json:"name"`     // 收款人姓名
	Status  int     `gorm:"default:0" json:"status"` // 0=待处理 1=已处理 2=已拒绝
	Remark  string  `gorm:"size:255" json:"remark"`

	ProcessedAt *time.Time `json:"processed_at"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

CommissionWithdraw 佣金提现

func (CommissionWithdraw) TableName

func (CommissionWithdraw) TableName() string

TableName 指定表名

type Coupon

type Coupon struct {
	ID           uint      `gorm:"primaryKey" json:"id"`
	Code         string    `gorm:"size:32;uniqueIndex" json:"code"`
	Name         string    `gorm:"size:255" json:"name"`
	Type         int       `gorm:"default:1" json:"type"`       // 1: percentage, 2: fixed amount
	Value        int       `json:"value"`                       // percentage (0-100) or amount in cents
	LimitUse     *int      `json:"limit_use"`                   // null or -1 = unlimited
	LimitUseWith *uint     `gorm:"index" json:"limit_use_with"` // limit to specific plan ID
	LimitPeriod  *string   `gorm:"size:20" json:"limit_period"` // limit to specific period
	UseCount     int       `gorm:"default:0" json:"use_count"`  // how many times used
	StartedAt    int64     `json:"started_at"`                  // unix timestamp
	EndedAt      int64     `json:"ended_at"`                    // unix timestamp
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

Coupon 优惠券模型

func (Coupon) TableName

func (Coupon) TableName() string

type CouponUsage

type CouponUsage struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	CouponID  uint      `gorm:"index" json:"coupon_id"`
	UserID    uint      `gorm:"index" json:"user_id"`
	OrderID   uint      `gorm:"index" json:"order_id"`
	CreatedAt time.Time `json:"created_at"`
}

CouponUsage 优惠券使用记录

func (CouponUsage) TableName

func (CouponUsage) TableName() string

type EPayConfig

type EPayConfig struct {
	APIURL    string `json:"api_url"`    // API地址
	PID       string `json:"pid"`        // 商户ID
	Key       string `json:"key"`        // 商户密钥
	NotifyURL string `json:"notify_url"` // 通知地址
	ReturnURL string `json:"return_url"` // 跳转地址
}

EPayConfig EPay配置

type EmailConfig

type EmailConfig struct {
	Host        string `json:"host"`         // SMTP服务器
	Port        int    `json:"port"`         // 端口
	Username    string `json:"username"`     // 用户名
	Password    string `json:"password"`     // 密码/授权码
	FromName    string `json:"from_name"`    // 发件人名称
	FromAddress string `json:"from_address"` // 发件人地址
	Encryption  string `json:"encryption"`   // ssl/tls/none
}

EmailConfig 邮件配置

type EncryptionSettings

type EncryptionSettings struct {
	Mode          string `json:"mode,omitempty"`           // 模式: native
	Ticket        string `json:"ticket,omitempty"`         // Ticket: 0rtt
	ServerPadding string `json:"server_padding,omitempty"` // 服务器填充
	PrivateKey    string `json:"private_key,omitempty"`    // 加密私钥
}

EncryptionSettings VLESS 加密设置 (mlkem768x25519plus)

type Event

type Event struct {
	ID          uint       `gorm:"primaryKey" json:"id"`
	Type        string     `gorm:"size:100;index" json:"type"` // e.g. plan.created, plan.updated, plan.assigned
	Payload     *string    `gorm:"type:text" json:"payload"`
	Status      string     `gorm:"size:20;default:'pending'" json:"status"`
	CreatedAt   time.Time  `json:"created_at"`
	ProcessedAt *time.Time `json:"processed_at"`
}

Event 简单事件表,用于记录管理员操作或异步任务

func (Event) TableName

func (Event) TableName() string

type Forward

type Forward struct {
	ID                uint           `gorm:"primaryKey" json:"id"`
	UserID            uint           `gorm:"index;not null" json:"user_id"`
	UserName          string         `gorm:"size:255" json:"user_name"`
	Name              string         `gorm:"size:100;not null" json:"name"`
	TunnelID          uint           `gorm:"index;not null" json:"tunnel_id"`
	Tunnel            *ForwardTunnel `gorm:"foreignKey:TunnelID" json:"tunnel,omitempty"`
	InPort            int            `gorm:"not null" json:"in_port"`
	OutPort           int            `json:"out_port"`
	RemoteAddr        string         `gorm:"type:text;not null" json:"remote_addr"`
	InterfaceName     string         `gorm:"size:255" json:"interface_name"`
	Strategy          string         `gorm:"size:20;default:'fifo'" json:"strategy"`
	Status            int            `gorm:"default:1" json:"status"`
	RuntimeBackend    string         `gorm:"size:50;default:'gost';index" json:"runtimeBackend"`
	RuntimeStatus     int            `gorm:"default:0;index" json:"runtimeStatus"`
	RuntimeMessage    string         `gorm:"type:text" json:"runtimeMessage"`
	RuntimeLastSyncAt *time.Time     `json:"runtimeLastSyncAt"`
	InFlow            int64          `gorm:"default:0" json:"in_flow"`
	OutFlow           int64          `gorm:"default:0" json:"out_flow"`
	Inx               int            `gorm:"default:0" json:"inx"`
	CreatedAt         time.Time      `json:"created_at"`
	UpdatedAt         time.Time      `json:"updated_at"`
	User              *User          `gorm:"foreignKey:UserID" json:"user,omitempty"`
}

Forward is the flux-panel compatible forward resource.

func (Forward) TableName

func (Forward) TableName() string

type ForwardAgentBridgeTask

type ForwardAgentBridgeTask struct {
	ID           uint      `gorm:"primaryKey" json:"id"`
	TaskID       string    `gorm:"size:80;uniqueIndex" json:"taskId"`
	RuntimeJobID uint      `gorm:"uniqueIndex" json:"runtimeJobId"`
	NodeID       uint      `gorm:"index" json:"nodeId"`
	ForwardID    *uint     `gorm:"index" json:"forwardId"`
	Action       string    `gorm:"size:30" json:"action"`
	Type         string    `gorm:"size:30" json:"type"`
	Params       string    `gorm:"type:text" json:"params"`
	Status       string    `gorm:"size:20;index" json:"status"`
	Dispatched   bool      `gorm:"default:false" json:"dispatched"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

ForwardAgentBridgeTask 持久化 clean_agent 转发任务的 task_id ↔ runtime_job 映射。 由于 /api/v2/agent/tasks 的内存任务表重启即丢,这张表用于让 bridge worker 下发的 任务在重启后仍可回溯,从而把 agent 上报结果准确回写到对应 runtime job 与 forward。

func (ForwardAgentBridgeTask) TableName

func (ForwardAgentBridgeTask) TableName() string

type ForwardCleanAgent

type ForwardCleanAgent struct {
	ID           uint       `gorm:"primaryKey" json:"id"`
	NodeID       *uint      `gorm:"index" json:"nodeId"`
	Name         string     `gorm:"size:100;not null" json:"name"`
	Token        string     `gorm:"size:160;not null;uniqueIndex" json:"-"`
	Version      string     `gorm:"size:50" json:"version"`
	Hostname     string     `gorm:"size:255" json:"hostname"`
	OS           string     `gorm:"size:50" json:"os"`
	Arch         string     `gorm:"size:50" json:"arch"`
	Kernel       string     `gorm:"size:120" json:"kernel"`
	PublicIP     string     `gorm:"size:64" json:"publicIp"`
	PrivateIP    string     `gorm:"size:64" json:"privateIp"`
	Capabilities string     `gorm:"type:text" json:"capabilities"`
	Status       int        `gorm:"default:0;index" json:"status"`
	LastSeen     *time.Time `gorm:"index" json:"lastSeen"`
	LastError    string     `gorm:"type:text" json:"lastError"`
	RevokedAt    *time.Time `json:"revokedAt"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
}

ForwardCleanAgent is the clean-room runtime worker used by the forward subsystem.

func (ForwardCleanAgent) TableName

func (ForwardCleanAgent) TableName() string

type ForwardLatencyBucket

type ForwardLatencyBucket struct {
	ID uint `gorm:"primaryKey" json:"id"`

	// 跨三类目标的统一键: "<type>:<id>:<host>:<port>"
	TargetKey  string `gorm:"size:191;not null;uniqueIndex:idx_flb_key_time,priority:1;index:idx_flb_key_latest,priority:1" json:"target_key"`
	TargetType string `gorm:"size:20;not null;index" json:"target_type"`
	TargetID   uint   `gorm:"index" json:"target_id"`
	Label      string `gorm:"size:191" json:"label"`
	Host       string `gorm:"size:255" json:"host"`
	Port       int    `json:"port"`

	BucketAt        time.Time `` /* 137-byte string literal not displayed */
	IntervalSeconds int       `gorm:"not null;default:60" json:"interval_seconds"`

	SampleCount  int     `gorm:"not null" json:"sample_count"`
	SuccessCount int     `gorm:"not null" json:"success_count"`
	MinRTT       float64 `json:"min_rtt"`  // ms
	AvgRTT       float64 `json:"avg_rtt"`  // ms
	MaxRTT       float64 `json:"max_rtt"`  // ms
	P95RTT       float64 `json:"p95_rtt"`  // ms
	LossPct      float64 `json:"loss_pct"` // 0..100

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ForwardLatencyBucket 一个探测目标在一个时间桶内的预聚合 TCPing 结果。 每行 = 一个 (目标 × 时间桶),不存原始单次样本。

func (ForwardLatencyBucket) TableName

func (ForwardLatencyBucket) TableName() string

TableName 指定表名

type ForwardLog

type ForwardLog struct {
	ID     uint  `gorm:"primaryKey" json:"id"`
	RuleID uint  `gorm:"index" json:"rule_id"`
	UserID *uint `gorm:"index" json:"user_id"`

	// 连接信息
	SourceIP   string `gorm:"size:50" json:"source_ip"`
	SourcePort int    `json:"source_port"`
	TargetHost string `gorm:"size:255" json:"target_host"`
	TargetPort int    `json:"target_port"`

	// 流量统计
	Upload   int64 `json:"upload"`
	Download int64 `json:"download"`
	Duration int64 `json:"duration"` // 持续时间(秒)

	// 节点信息
	RelayNodeID uint `json:"relay_node_id"`
	ExitNodeID  uint `json:"exit_node_id"`

	// 状态
	Status string `gorm:"size:20" json:"status"` // success/timeout/error
	Error  string `gorm:"size:500" json:"error"`

	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

ForwardLog 转发日志

func (ForwardLog) TableName

func (ForwardLog) TableName() string

TableName 指定表名

type ForwardNode

type ForwardNode struct {
	ID          uint   `gorm:"primaryKey" json:"id"`
	Name        string `gorm:"size:100;not null" json:"name"`
	Type        string `gorm:"size:20;not null;default:'exit'" json:"type"` // relay/exit
	Host        string `gorm:"size:255;not null" json:"host"`
	Port        int    `gorm:"not null" json:"port"`
	APIPort     int    `json:"api_port"` // 管理API端口
	APIToken    string `gorm:"size:100" json:"api_token"`
	MetricsPort int    `json:"metrics_port"` // Prometheus /metrics 端口,0 表示未配置

	// 节点信息
	Region     string `gorm:"size:50" json:"region"`      // 地区: HK, US, JP, SG等
	ISP        string `gorm:"size:50" json:"isp"`         // 运营商
	Datacenter string `gorm:"size:100" json:"datacenter"` // 数据中心
	Bandwidth  int64  `json:"bandwidth"`                  // 带宽(Mbps)

	// 状态
	Status    int       `gorm:"default:0" json:"status"`
	LastCheck time.Time `json:"last_check"`
	Latency   int       `json:"latency"` // 延迟(ms)
	Load      float64   `json:"load"`    // 负载 0-1
	Uptime    float64   `json:"uptime"`  // 在线率 0-100

	// 配置
	Tags    string `gorm:"type:text" json:"tags"`   // JSON数组
	Weight  int    `gorm:"default:1" json:"weight"` // 负载均衡权重
	MaxConn int    `json:"max_conn"`                // 最大连接数
	Enabled bool   `gorm:"default:true" json:"enabled"`

	// 统计
	TotalUpload   int64 `json:"total_upload"`
	TotalDownload int64 `json:"total_download"`
	CurrentConn   int   `json:"current_conn"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ForwardNode 中转/落地节点

func (ForwardNode) TableName

func (ForwardNode) TableName() string

TableName 指定表名

type ForwardPortBinding

type ForwardPortBinding struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	ForwardID  uint      `gorm:"index;not null" json:"forwardId"`
	NodeID     uint      `gorm:"not null;uniqueIndex:idx_forward_port_binding_socket,priority:1" json:"nodeId"`
	Transport  string    `gorm:"size:10;not null;uniqueIndex:idx_forward_port_binding_socket,priority:2" json:"transport"`
	ListenAddr string    `gorm:"size:255;not null;uniqueIndex:idx_forward_port_binding_socket,priority:3" json:"listenAddr"`
	InPort     int       `gorm:"not null;uniqueIndex:idx_forward_port_binding_socket,priority:4" json:"inPort"`
	CreatedAt  time.Time `json:"createdAt"`
	UpdatedAt  time.Time `json:"updatedAt"`

	Forward *Forward `gorm:"foreignKey:ForwardID" json:"forward,omitempty"`
}

ForwardPortBinding records the concrete socket claims owned by a panel forward. It gives port assignment a database-level exact-conflict guard while the service layer still handles wildcard listen-address overlap semantics.

func (ForwardPortBinding) TableName

func (ForwardPortBinding) TableName() string

type ForwardRoute

type ForwardRoute struct {
	ID       uint   `gorm:"primaryKey" json:"id"`
	Name     string `gorm:"size:100;not null" json:"name"`
	Priority int    `gorm:"default:0" json:"priority"` // 优先级,数字越大越优先
	Enabled  bool   `gorm:"default:true" json:"enabled"`

	// 匹配条件 (所有条件为AND关系)
	SourceIP  string `gorm:"size:100" json:"source_ip"` // 源IP/网段,支持CIDR,多个用逗号分隔
	Region    string `gorm:"size:50" json:"region"`     // 来源地区
	PortRange string `gorm:"size:50" json:"port_range"` // 端口范围: 80-443,8080
	Protocol  string `gorm:"size:20" json:"protocol"`   // 协议: tcp/udp/both

	// 目标节点
	RelayGroup  string `gorm:"size:50" json:"relay_group"` // 中转节点组名
	ExitGroup   string `gorm:"size:50" json:"exit_group"`  // 落地节点组名
	RelayNodeID *uint  `json:"relay_node_id"`              // 或指定特定节点
	ExitNodeID  *uint  `json:"exit_node_id"`

	// 负载均衡
	BalanceMode string `gorm:"size:20;default:'round-robin'" json:"balance_mode"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ForwardRoute 智能路由规则

func (ForwardRoute) TableName

func (ForwardRoute) TableName() string

TableName 指定表名

type ForwardRule

type ForwardRule struct {
	ID      uint   `gorm:"primaryKey" json:"id"`
	Name    string `gorm:"size:100;not null" json:"name"`
	Enabled bool   `gorm:"default:true" json:"enabled"`

	// 入口配置 (中转节点)
	RelayNodeID uint         `gorm:"not null" json:"relay_node_id"`
	RelayNode   *ForwardNode `gorm:"foreignKey:RelayNodeID" json:"relay_node,omitempty"`
	ListenPort  int          `gorm:"not null" json:"listen_port"`           // 监听端口
	Protocol    string       `gorm:"size:10;default:'tcp'" json:"protocol"` // tcp/udp/both

	// 出口配置 (落地节点)
	ExitNodeID uint         `gorm:"not null" json:"exit_node_id"`
	ExitNode   *ForwardNode `gorm:"foreignKey:ExitNodeID" json:"exit_node,omitempty"`
	TargetHost string       `gorm:"size:255;not null" json:"target_host"` // 目标地址
	TargetPort int          `gorm:"not null" json:"target_port"`          // 目标端口

	// 用户绑定 (可选,为空则为公共规则)
	UserID      *uint `json:"user_id"`
	User        *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
	UserGroupID *uint `json:"user_group_id"`

	// IP allowlist (comma-separated CIDRs or single IPs, empty = allow all)
	AllowedIPs string `gorm:"size:1000" json:"allowed_ips"`

	// 流量控制
	SpeedLimit   *int64     `json:"speed_limit"`   // 速度限制(KB/s), nil为不限
	TrafficLimit *int64     `json:"traffic_limit"` // 流量限制(字节), nil为不限
	ExpireTime   *time.Time `json:"expire_time"`   // 过期时间, nil为永不过期

	// 统计
	Upload      int64 `json:"upload"`
	Download    int64 `json:"download"`
	Connections int   `json:"connections"` // 当前连接数
	TotalConns  int64 `json:"total_conns"` // 累计连接数

	// 其他
	Remark    string    `gorm:"size:500" json:"remark"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ForwardRule 转发规则

func (ForwardRule) TableName

func (ForwardRule) TableName() string

TableName 指定表名

type ForwardRuntimeJob

type ForwardRuntimeJob struct {
	ID           uint       `gorm:"primaryKey" json:"id"`
	Backend      string     `gorm:"size:50;not null;index" json:"backend"`
	Action       string     `gorm:"size:30;not null;index" json:"action"`
	ResourceType string     `gorm:"size:30;index" json:"resourceType"`
	ResourceID   *uint      `json:"resourceId"`
	ForwardID    *uint      `gorm:"index" json:"forwardId"`
	TunnelID     *uint      `gorm:"index" json:"tunnelId"`
	NodeID       *uint      `gorm:"index" json:"nodeId"`
	AgentID      *uint      `gorm:"index" json:"agentId"`
	Status       int        `gorm:"default:0;index" json:"status"`
	Payload      string     `gorm:"type:text" json:"payload"`
	Result       string     `gorm:"type:text" json:"result"`
	Error        string     `gorm:"type:text" json:"error"`
	StartedAt    *time.Time `json:"startedAt"`
	ClaimedAt    *time.Time `json:"claimedAt"`
	CompletedAt  *time.Time `json:"completedAt"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
}

ForwardRuntimeJob records non-DB runtime actions for forward-compatible runtimes.

func (ForwardRuntimeJob) TableName

func (ForwardRuntimeJob) TableName() string

type ForwardStats

type ForwardStats struct {
	ID     uint  `gorm:"primaryKey" json:"id"`
	NodeID uint  `gorm:"index" json:"node_id"`
	RuleID uint  `gorm:"index" json:"rule_id"`
	UserID *uint `gorm:"index" json:"user_id"`

	// 时间
	Date time.Time `gorm:"type:date" json:"date"` // 日期
	Hour int       `json:"hour"`                  // 小时 0-23

	// 流量
	Upload      int64 `json:"upload"`
	Download    int64 `json:"download"`
	Connections int64 `json:"connections"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ForwardStats 转发统计 (按小时聚合)

func (ForwardStats) TableName

func (ForwardStats) TableName() string

TableName 指定表名

type ForwardTrafficCursor

type ForwardTrafficCursor struct {
	ID            uint      `gorm:"primaryKey" json:"id"`
	ForwardID     uint      `gorm:"uniqueIndex:idx_forward_traffic_cursor" json:"forwardId"`
	Backend       string    `gorm:"size:50;uniqueIndex:idx_forward_traffic_cursor" json:"backend"`
	UploadTotal   int64     `gorm:"default:0" json:"uploadTotal"`
	DownloadTotal int64     `gorm:"default:0" json:"downloadTotal"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

ForwardTrafficCursor stores the last runtime totals seen for a forward/backend pair so snapshot-based collectors can safely convert cumulative counters into deltas.

func (ForwardTrafficCursor) TableName

func (ForwardTrafficCursor) TableName() string

type ForwardTunnel

type ForwardTunnel struct {
	ID            uint      `gorm:"primaryKey" json:"id"`
	Name          string    `gorm:"size:100;not null" json:"name"`
	InNodeID      uint      `gorm:"index" json:"inNodeId"`
	OutNodeID     *uint     `gorm:"index" json:"outNodeId"`
	InIP          string    `gorm:"size:255" json:"in_ip"`
	OutIP         string    `gorm:"size:255" json:"out_ip"`
	InNodePortSta *int      `json:"in_node_port_sta"`
	InNodePortEnd *int      `json:"in_node_port_end"`
	Type          int       `gorm:"default:1" json:"type"`
	Flow          int       `gorm:"default:2" json:"flow"`
	Protocol      string    `gorm:"size:30;default:'tcp'" json:"protocol"`
	TrafficRatio  float64   `gorm:"default:1" json:"traffic_ratio"`
	InterfaceName string    `gorm:"size:255" json:"interface_name"`
	TCPListenAddr string    `gorm:"size:255;default:'0.0.0.0'" json:"tcpListenAddr"`
	UDPListenAddr string    `gorm:"size:255;default:'0.0.0.0'" json:"udpListenAddr"`
	Status        int       `gorm:"default:1" json:"status"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

ForwardTunnel is the minimal tunnel resource required by the flux-panel style forward page.

func (ForwardTunnel) TableName

func (ForwardTunnel) TableName() string

type ForwardUserTunnel

type ForwardUserTunnel struct {
	ID            uint      `gorm:"primaryKey" json:"id"`
	UserID        uint      `gorm:"uniqueIndex:idx_forward_user_tunnel" json:"user_id"`
	TunnelID      uint      `gorm:"uniqueIndex:idx_forward_user_tunnel;index" json:"tunnel_id"`
	Flow          int64     `gorm:"default:0" json:"flow"`
	Num           int       `gorm:"default:0" json:"num"`
	InFlow        int64     `gorm:"default:0" json:"in_flow"`
	OutFlow       int64     `gorm:"default:0" json:"out_flow"`
	FlowResetTime int64     `gorm:"default:0" json:"flowResetTime"`
	ExpTime       int64     `gorm:"default:0" json:"expTime"`
	SpeedID       *uint     `json:"speedId"`
	Status        int       `gorm:"default:1" json:"status"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`

	User   *User          `gorm:"foreignKey:UserID" json:"user,omitempty"`
	Tunnel *ForwardTunnel `gorm:"foreignKey:TunnelID" json:"tunnel,omitempty"`
}

ForwardUserTunnel stores flux-panel style per-user tunnel authorization.

func (ForwardUserTunnel) TableName

func (ForwardUserTunnel) TableName() string

type InviteCode

type InviteCode struct {
	ID        uint       `gorm:"primaryKey" json:"id"`
	Code      string     `gorm:"size:32;uniqueIndex" json:"code"`
	UserID    *uint      `gorm:"index" json:"user_id"`    // 所属用户 (null=公共)
	Status    int        `gorm:"default:0" json:"status"` // 0=未使用 1=已使用
	UsedBy    *uint      `json:"used_by"`                 // 使用者ID
	UsedAt    *time.Time `json:"used_at"`
	ExpiredAt *time.Time `json:"expired_at"` // 过期时间 (null=永不过期)

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

InviteCode 邀请码

func (InviteCode) TableName

func (InviteCode) TableName() string

TableName 指定表名

type InviteConfig

type InviteConfig struct {
	ID      uint `gorm:"primaryKey" json:"id"`
	Enabled bool `gorm:"default:true" json:"enabled"`

	// 邀请码设置
	AutoGenerate   bool `gorm:"default:true" json:"auto_generate"` // 新用户自动生成邀请码
	CodeCount      int  `gorm:"default:5" json:"code_count"`       // 每个用户邀请码数量
	CodeExpireDays int  `gorm:"default:0" json:"code_expire_days"` // 邀请码过期天数 (0=永不过期)

	// 佣金设置
	CommissionEnabled   bool    `gorm:"default:true" json:"commission_enabled"` // 是否启用佣金
	CommissionType      int     `gorm:"default:1" json:"commission_type"`       // 1=按比例 2=固定金额
	CommissionRate      float64 `gorm:"default:0.1" json:"commission_rate"`     // 佣金比例 (0.1 = 10%)
	CommissionFixed     float64 `gorm:"default:0" json:"commission_fixed"`      // 固定佣金金额
	CommissionMinAmount float64 `gorm:"default:10" json:"commission_min"`       // 最低提现金额

	// 首次奖励
	FirstOrderBonus   float64 `gorm:"default:0" json:"first_order_bonus"`   // 首单奖励
	FirstTrafficBonus int64   `gorm:"default:0" json:"first_traffic_bonus"` // 首次流量奖励 (bytes)

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

InviteConfig 邀请配置

func (InviteConfig) TableName

func (InviteConfig) TableName() string

TableName 指定表名

type KernelOperation

type KernelOperation struct {
	ID              string `gorm:"primaryKey;size:64" json:"id"`
	IdempotencyKey  string `gorm:"size:160;not null;uniqueIndex" json:"idempotency_key"`
	EnvelopeVersion string `gorm:"size:32;not null;default:anixops.operation/v1" json:"envelope_version"`
	// SessionID is written by the dispatcher from the active Agent connection.
	// It must never be trusted from an HTTP request.
	SessionID            string `gorm:"size:120;index" json:"session_id"`
	NodeID               *uint  `gorm:"index" json:"node_id"`
	PluginID             string `gorm:"size:120;index" json:"plugin_id"`
	TargetVersion        string `gorm:"size:64" json:"target_version"`
	TopologyDeploymentID *uint  `gorm:"index" json:"topology_deployment_id"`
	TopologyStepID       *uint  `gorm:"index" json:"topology_step_id"`
	TopologyRevision     int64  `gorm:"not null;default:0" json:"topology_revision"`
	Kind                 string `gorm:"size:80;not null" json:"kind"`
	Revision             int64  `gorm:"not null" json:"revision"`
	ConfigJSON           string `gorm:"type:text;not null;default:{}" json:"config"`
	ConfigHash           string `gorm:"size:64" json:"config_hash"`
	DependsOnOperationID string `gorm:"size:64;index" json:"depends_on_operation_id,omitempty"`
	// LifecyclePlanID and the following fields group Control-target package
	// operations that must be executed as one dependency-aware lifecycle plan.
	// They are intentionally empty for legacy and Agent operations.
	LifecyclePlanID       string     `gorm:"size:64;index" json:"lifecycle_plan_id,omitempty"`
	LifecyclePlanStepID   uint       `gorm:"index" json:"lifecycle_plan_step_id,omitempty"`
	LifecyclePlanPhase    string     `gorm:"size:16;index" json:"lifecycle_plan_phase,omitempty"`
	LifecyclePlanSequence int        `gorm:"not null;default:0;index" json:"lifecycle_plan_sequence"`
	State                 string     `gorm:"size:32;not null;index" json:"state"`
	DeadlineAt            *time.Time `json:"deadline_at"`
	DispatchedAt          *time.Time `json:"dispatched_at"`
	AcknowledgedAt        *time.Time `json:"acknowledged_at"`
	ObservedAt            *time.Time `json:"observed_at"`
	CancelAt              *time.Time `json:"cancel_at"`
	CancelDispatchedAt    *time.Time `json:"cancel_dispatched_at"`
	ClaimedBy             string     `gorm:"size:96;index" json:"claimed_by"`
	LeaseExpiresAt        *time.Time `gorm:"index" json:"lease_expires_at"`
	Attempt               int        `gorm:"not null;default:0" json:"attempt"`
	ResultJSON            string     `gorm:"type:text" json:"result"`
	LastError             string     `gorm:"type:text" json:"last_error"`
	CreatedAt             time.Time  `json:"created_at"`
	UpdatedAt             time.Time  `json:"updated_at"`
}

func (KernelOperation) TableName

func (KernelOperation) TableName() string

type Knowledge

type Knowledge struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Category  string    `gorm:"size:64" json:"category"`
	Title     string    `gorm:"size:255" json:"title"`
	Body      string    `gorm:"type:text" json:"body"`
	Sort      int       `gorm:"default:0" json:"sort"`
	Show      int       `gorm:"default:1" json:"show"` // 0: hidden, 1: visible
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Knowledge 知识库文章模型

func (Knowledge) TableName

func (Knowledge) TableName() string

type LoadBalancer

type LoadBalancer struct {
	ID            uint      `gorm:"primaryKey" json:"id"`
	Name          string    `gorm:"size:100" json:"name"`
	GroupID       uint      `gorm:"index" json:"group_id"`                       // 节点组ID
	Strategy      string    `gorm:"size:20;default:round-robin" json:"strategy"` // round-robin/least-conn/latency/weight/random
	HealthCheck   bool      `gorm:"default:true" json:"health_check"`
	CheckInterval int       `gorm:"default:60" json:"check_interval"` // 检查间隔(秒)
	CheckTimeout  int       `gorm:"default:10" json:"check_timeout"`  // 超时时间(秒)
	NodeWeights   string    `gorm:"type:text" json:"node_weights"`    // JSON: {node_id: weight}
	Enabled       bool      `gorm:"default:true" json:"enabled"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

LoadBalancer 负载均衡器

func (LoadBalancer) TableName

func (LoadBalancer) TableName() string

TableName 指定表名

type LoginRequest

type LoginRequest struct {
	Email     string `json:"email" binding:"required,email"`
	Password  string `json:"password" binding:"required"`
	MFACode   string `json:"mfa_code"`
	MFAMethod string `json:"mfa_method"`
}

LoginRequest 登录请求

type LoginResponse

type LoginResponse struct {
	Token   string `json:"token"`
	IsAdmin bool   `json:"is_admin"`
}

LoginResponse 登录响应

type MFAConfig

type MFAConfig struct {
	Enabled         bool   `json:"enabled"`           // 是否启用MFA
	EnforceForAll   bool   `json:"enforce_for_all"`   // 强制所有用户启用
	EnforceForAdmin bool   `json:"enforce_for_admin"` // 强制管理员启用
	AllowedMethods  string `json:"allowed_methods"`   // 允许的方式 (JSON数组)
	TOTPIssuer      string `json:"totp_issuer"`       // TOTP发行者名称
	BackupCodeCount int    `json:"backup_code_count"` // 备用码数量
}

MFAConfig MFA全局配置

type MFALoginAttempt

type MFALoginAttempt struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	UserID    uint      `gorm:"index" json:"user_id"`
	IP        string    `gorm:"size:50" json:"ip"`
	UserAgent string    `gorm:"size:255" json:"user_agent"`
	Success   bool      `json:"success"`
	Method    string    `gorm:"size:20" json:"method"` // totp/sms/email/backup
	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

MFALoginAttempt MFA登录尝试

func (MFALoginAttempt) TableName

func (MFALoginAttempt) TableName() string

TableName 指定表名

type Node

type Node struct {
	ID           uint       `gorm:"primaryKey" json:"id"`
	Name         string     `gorm:"size:255" json:"name"`           // 节点名称
	Host         string     `gorm:"size:255" json:"host"`           // 服务器地址 (IP或域名)
	Port         int        `gorm:"default:443" json:"port"`        // API通信端口
	APIKey       string     `gorm:"size:64;uniqueIndex" json:"-"`   // 节点API密钥 (用于身份验证)
	APIKeyHash   string     `gorm:"size:64" json:"-"`               // 密钥哈希 (用于快速查找)
	Secret       string     `gorm:"size:255" json:"-"`              // 共享密钥 (用于加密通信)
	Status       NodeStatus `gorm:"default:0" json:"status"`        // 节点状态
	Tags         *string    `gorm:"size:255" json:"tags"`           // 标签 (JSON array)
	GroupID      *uint      `gorm:"index" json:"group_id"`          // 节点分组
	Rate         float64    `gorm:"default:1" json:"rate"`          // 流量倍率
	TrafficRate  float64    `gorm:"default:1" json:"traffic_rate"`  // 计费倍率
	Sort         int        `gorm:"default:0" json:"sort"`          // 排序
	Show         int        `gorm:"default:1" json:"show"`          // 是否显示给用户
	AutoRegister int        `gorm:"default:0" json:"auto_register"` // 是否自动注册的节点

	// 父子节点 (中转链路: 落地节点为根, 转发节点为子, 支持多级)
	ParentID *uint `gorm:"index" json:"parent_id"` // 上级节点ID, nil=根节点(落地节点)

	// 月流量限额 (仅本节点自身, 不含子节点单独限额; 子节点流量会同时累加到父节点)
	MonthlyLimit    *int64 `json:"monthly_limit"`                      // 月流量限额(字节), nil=不限
	MonthlyUpload   int64  `gorm:"default:0" json:"monthly_upload"`    // 本月已用上传流量
	MonthlyDownload int64  `gorm:"default:0" json:"monthly_download"`  // 本月已用下载流量
	MonthlyResetDay int    `gorm:"default:1" json:"monthly_reset_day"` // 每月流量重置日 (1-28)

	// 高级配置 (直接JSON编辑)
	RawConfig *string `gorm:"type:text" json:"raw_config"` // 原始配置 (JSON, 优先级最高)

	// 服务器信息 (由节点上报)
	ServerIP      *string `gorm:"size:45" json:"server_ip"`      // 实际服务器IP
	ServerVersion *string `gorm:"size:50" json:"server_version"` // 节点程序版本
	ServerOS      *string `gorm:"size:100" json:"server_os"`     // 操作系统信息
	CPUUsage      float64 `gorm:"default:0" json:"cpu_usage"`    // CPU使用率
	MemoryUsage   float64 `gorm:"default:0" json:"memory_usage"` // 内存使用率
	DiskUsage     float64 `gorm:"default:0" json:"disk_usage"`   // 磁盘使用率
	Uptime        int64   `gorm:"default:0" json:"uptime"`       // 运行时间(秒)
	OnlineUsers   int     `gorm:"default:0" json:"online_users"` // 在线用户数

	// 运行时健康状态 (由支持运行时自愈的节点上报)
	RuntimeHealthy   bool   `gorm:"default:true" json:"runtime_healthy"`
	RuntimeError     string `gorm:"type:text" json:"runtime_error"`
	RuntimeCheckedAt *int64 `json:"runtime_checked_at"`

	// 流量统计
	TotalUpload   int64 `gorm:"default:0" json:"total_upload"`   // 总上传流量
	TotalDownload int64 `gorm:"default:0" json:"total_download"` // 总下载流量

	// 时间戳
	LastCheckAt *int64    `json:"last_check_at"` // 最后心跳时间
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`

	// 关联
	Protocols []NodeProtocol `gorm:"foreignKey:NodeID" json:"protocols,omitempty"`
}

Node 节点模型 (物理服务器)

func (*Node) IsOnline

func (n *Node) IsOnline() bool

IsOnline 检查节点是否在线 (5分钟内有心跳)

func (Node) TableName

func (Node) TableName() string

type NodeGroup

type NodeGroup struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"size:100" json:"name"`
	Sort      int       `gorm:"default:0" json:"sort"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

NodeGroup 节点分组

func (NodeGroup) TableName

func (NodeGroup) TableName() string

type NodeHeartbeatRequest

type NodeHeartbeatRequest struct {
	CPUUsage    float64 `json:"cpu_usage"`
	MemoryUsage float64 `json:"memory_usage"`
	DiskUsage   float64 `json:"disk_usage"`
	Uptime      int64   `json:"uptime"`
	OnlineUsers int     `json:"online_users"`
	Upload      int64   `json:"upload"`   // 本次上传流量增量
	Download    int64   `json:"download"` // 本次下载流量增量
}

NodeHeartbeatRequest 节点心跳请求

type NodeLog

type NodeLog struct {
	ID         uint       `gorm:"primaryKey" json:"id"`
	NodeID     uint       `gorm:"index;not null" json:"node_id"`
	Level      string     `gorm:"size:20;index;not null" json:"level"`
	Source     string     `gorm:"size:120;index" json:"source"`
	Message    string     `gorm:"type:text;not null" json:"message"`
	TraceID    string     `gorm:"size:120;index" json:"trace_id"`
	FieldsJSON string     `gorm:"type:text" json:"fields_json"`
	LoggedAt   *time.Time `gorm:"index" json:"logged_at"`
	CreatedAt  time.Time  `gorm:"index" json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

NodeLog stores runtime logs reported by V2bX parent nodes over gRPC.

func (NodeLog) TableName

func (NodeLog) TableName() string

type NodeOperationRevision

type NodeOperationRevision struct {
	NodeID           uint      `gorm:"primaryKey" json:"node_id"`
	DesiredRevision  int64     `gorm:"not null;default:0" json:"desired_revision"`
	ObservedRevision int64     `gorm:"not null;default:0" json:"observed_revision"`
	UpdatedAt        time.Time `json:"updated_at"`
}

NodeOperationRevision is the durable desired/observed revision cursor for a physical node. It is intentionally separate from any plugin-specific state.

func (NodeOperationRevision) TableName

func (NodeOperationRevision) TableName() string

type NodePluginLifecycle

type NodePluginLifecycle struct {
	NodeID                uint       `gorm:"primaryKey" json:"node_id"`
	PluginID              string     `gorm:"primaryKey;size:120" json:"plugin_id"`
	DesiredGeneration     int64      `gorm:"not null;default:0" json:"desired_generation"`
	RetryEpoch            int        `gorm:"not null;default:0" json:"retry_epoch"`
	RetryAfter            *time.Time `gorm:"index" json:"retry_after"`
	RetryExhausted        bool       `gorm:"not null;default:false" json:"retry_exhausted"`
	DesiredVersion        string     `gorm:"size:64" json:"desired_version"`
	DesiredConfigRevision int64      `gorm:"not null;default:0" json:"desired_config_revision"`
	DesiredEnabled        bool       `gorm:"not null;default:false" json:"desired_enabled"`
	ActiveVersion         string     `gorm:"size:64" json:"active_version"`
	ActiveEnabled         bool       `gorm:"not null;default:false" json:"active_enabled"`
	ActiveRevision        int64      `gorm:"not null;default:0" json:"active_revision"`
	LastError             string     `gorm:"type:text" json:"last_error"`
	CreatedAt             time.Time  `json:"created_at"`
	UpdatedAt             time.Time  `json:"updated_at"`
}

NodePluginLifecycle is the aggregate desired/observed boundary for all roles of one plugin on one physical node. The row is also the transaction lock that serializes assignment, configuration, retry and deletion intent.

func (NodePluginLifecycle) TableName

func (NodePluginLifecycle) TableName() string

type NodePluginObservedState

type NodePluginObservedState struct {
	NodeID           uint      `gorm:"primaryKey" json:"node_id"`
	PluginID         string    `gorm:"primaryKey;size:120" json:"plugin_id"`
	Version          string    `gorm:"size:64;not null" json:"version"`
	DesiredRevision  int64     `gorm:"not null" json:"desired_revision"`
	ObservedRevision int64     `gorm:"not null" json:"observed_revision"`
	ConfigHash       string    `gorm:"size:64;not null" json:"config_hash"`
	Health           string    `gorm:"size:32;not null;index" json:"health"`
	RulesetSHA256    string    `gorm:"size:64;not null" json:"ruleset_sha256"`
	CountersJSON     string    `gorm:"type:text;not null;default:[]" json:"rule_counters"`
	ObservedAt       time.Time `gorm:"not null;index" json:"observed_at"`
	ReceivedAt       time.Time `gorm:"not null;index" json:"received_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

NodePluginObservedState is a bounded, non-secret snapshot emitted by an Agent plugin. It is intentionally separate from generic telemetry because topology promotion needs a cryptographically bound config/ruleset view, rather than a plugin-defined metric bag.

func (NodePluginObservedState) TableName

func (NodePluginObservedState) TableName() string

type NodeProtocol

type NodeProtocol struct {
	ID      uint         `gorm:"primaryKey" json:"id"`
	NodeID  uint         `gorm:"index" json:"node_id"`      // 所属节点
	Name    string       `gorm:"size:100" json:"name"`      // 协议名称
	Type    ProtocolType `gorm:"size:20;index" json:"type"` // 协议类型
	Port    int          `json:"port"`                      // 监听端口
	Enable  int          `gorm:"default:1" json:"enable"`   // 是否启用 (节点端是否运行)
	Show    int          `gorm:"default:1" json:"show"`     // 是否显示在订阅中
	Sort    int          `gorm:"default:0" json:"sort"`     // 排序
	GroupID *uint        `gorm:"index" json:"group_id"`     // 所属订阅分组 (如果为空则跟随节点)

	// 通用配置
	Host *string `gorm:"size:255" json:"host"` // 连接地址 (可覆盖节点host)
	TLS  int     `gorm:"default:0" json:"tls"` // TLS模式: 0=无, 1=TLS, 2=Reality
	ALPN *string `gorm:"size:100" json:"alpn"` // ALPN设置

	// 协议特定配置 (JSON)
	Settings          *string `gorm:"type:text" json:"settings"`           // 协议配置 (JSON)
	TLSSettings       *string `gorm:"type:text" json:"tls_settings"`       // TLS配置 (JSON)
	Transport         *string `gorm:"size:20" json:"transport"`            // 传输层: tcp, ws, grpc, quic, h2
	TransportSettings *string `gorm:"type:text" json:"transport_settings"` // 传输层配置 (JSON)

	// Reality 配置
	RealitySettings *string `gorm:"type:text" json:"reality_settings"` // Reality配置 (JSON)

	// 自定义配置 (全量覆盖)
	CustomConfig *string `gorm:"type:text" json:"custom_config"` // 自定义配置 (JSON, 优先级最高)

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	// 关联
	Node               *Node               `gorm:"foreignKey:NodeID" json:"node,omitempty"`
	SubscriptionGroups []SubscriptionGroup `gorm:"many2many:v2_subscription_group_node_protocols;" json:"subscription_groups,omitempty"`
}

NodeProtocol 节点协议配置

func (NodeProtocol) TableName

func (NodeProtocol) TableName() string

type NodeRegisterRequest

type NodeRegisterRequest struct {
	AuthKey       string `json:"auth_key" binding:"required"` // 授权密钥
	Name          string `json:"name"`                        // 节点名称
	Host          string `json:"host"`                        // 节点地址
	Port          int    `json:"port"`                        // API端口
	ServerVersion string `json:"server_version"`              // 节点版本
	ServerOS      string `json:"server_os"`                   // 操作系统
}

NodeRegisterRequest 节点注册请求

type NodeRegisterResponse

type NodeRegisterResponse struct {
	NodeID  uint   `json:"node_id"`
	APIKey  string `json:"api_key"` // 返回给节点的API密钥
	Secret  string `json:"secret"`  // 共享密钥
	Message string `json:"message"`
}

NodeRegisterResponse 节点注册响应

type NodeRuntimeHealthRequest

type NodeRuntimeHealthRequest struct {
	Healthy bool   `json:"healthy"`
	Error   string `json:"error"`
}

NodeRuntimeHealthRequest reports process-level runtime health separately from the regular system heartbeat metrics.

type NodeServiceAssignment

type NodeServiceAssignment struct {
	ID                    uint      `gorm:"primaryKey" json:"id"`
	NodeID                uint      `gorm:"not null;index;uniqueIndex:ux_node_service_assignment" json:"node_id"`
	ServiceScope          string    `gorm:"size:64;not null;uniqueIndex:ux_node_service_assignment" json:"service_scope"`
	PluginID              string    `gorm:"size:120;not null;uniqueIndex:ux_node_service_assignment" json:"plugin_id"`
	Role                  string    `gorm:"size:80;not null;uniqueIndex:ux_node_service_assignment" json:"role"`
	DesiredVersion        string    `gorm:"size:64" json:"desired_version"`
	DesiredConfigRevision int64     `gorm:"not null;default:0" json:"desired_config_revision"`
	Enabled               bool      `gorm:"not null" json:"enabled"`
	LifecycleGeneration   int64     `gorm:"not null;default:0" json:"lifecycle_generation"`
	DeletePending         bool      `gorm:"not null;default:false;index" json:"delete_pending"`
	RolloutGroup          string    `gorm:"size:80;index" json:"rollout_group"`
	CreatedAt             time.Time `json:"created_at"`
	UpdatedAt             time.Time `json:"updated_at"`
}

func (NodeServiceAssignment) TableName

func (NodeServiceAssignment) TableName() string

type NodeStatus

type NodeStatus int

NodeStatus 节点状态

const (
	NodeStatusPending  NodeStatus = 0 // 待审核
	NodeStatusOnline   NodeStatus = 1 // 在线
	NodeStatusOffline  NodeStatus = 2 // 离线
	NodeStatusDisabled NodeStatus = 3 // 已禁用
)

type NotificationLog

type NotificationLog struct {
	ID        uint       `gorm:"primaryKey" json:"id"`
	UserID    *uint      `gorm:"index" json:"user_id"`
	Type      string     `gorm:"size:20" json:"type"`  // email/telegram/webhook
	Event     string     `gorm:"size:50" json:"event"` // 触发事件
	Title     string     `gorm:"size:200" json:"title"`
	Content   string     `gorm:"type:text" json:"content"`
	Status    int        `json:"status"` // 0=待发送 1=已发送 2=失败
	Error     string     `gorm:"size:500" json:"error"`
	SentAt    *time.Time `json:"sent_at"`
	ReadAt    *time.Time `json:"read_at"`
	CreatedAt time.Time  `gorm:"index" json:"created_at"`
}

NotificationLog 通知日志

func (NotificationLog) TableName

func (NotificationLog) TableName() string

TableName 指定表名

type NotificationTemplate

type NotificationTemplate struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"size:100;not null" json:"name"`
	Type      string    `gorm:"size:20;not null" json:"type"`  // email/telegram/webhook
	Event     string    `gorm:"size:50;not null" json:"event"` // 触发事件
	Title     string    `gorm:"size:200" json:"title"`         // 标题模板
	Content   string    `gorm:"type:text" json:"content"`      // 内容模板
	Enabled   bool      `gorm:"default:true" json:"enabled"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

NotificationTemplate 通知模板

func (NotificationTemplate) TableName

func (NotificationTemplate) TableName() string

TableName 指定表名

type OnlineLog

type OnlineLog struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	UserID     uint      `gorm:"index" json:"user_id"`
	ServerID   uint      `gorm:"index" json:"server_id"`
	ServerType string    `gorm:"size:20" json:"server_type"`
	Method     string    `gorm:"size:20" json:"method"`
	IP         string    `gorm:"size:45" json:"ip"`
	CreatedAt  time.Time `json:"created_at"`
}

OnlineLog 在线日志

func (OnlineLog) TableName

func (OnlineLog) TableName() string

type OperationLog

type OperationLog struct {
	ID         uint   `gorm:"primaryKey" json:"id"`
	UserID     *uint  `gorm:"index" json:"user_id"`
	Username   string `gorm:"size:100" json:"username"`
	Action     string `gorm:"size:50;index" json:"action"` // create/update/delete/login/logout
	Module     string `gorm:"size:50;index" json:"module"` // user/node/order/plan...
	TargetType string `gorm:"size:50" json:"target_type"`  // 目标类型
	TargetID   *uint  `json:"target_id"`                   // 目标ID
	Content    string `gorm:"type:text" json:"content"`    // 操作内容
	IP         string `gorm:"size:45" json:"ip"`
	UserAgent  string `gorm:"size:255" json:"user_agent"`
	Status     int    `gorm:"default:1" json:"status"` // 1=成功 2=失败

	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

OperationLog 操作日志

func (OperationLog) TableName

func (OperationLog) TableName() string

TableName 指定表名

type Order

type Order struct {
	ID                uint      `gorm:"primaryKey" json:"id"`
	InviteUserID      *uint     `gorm:"index" json:"invite_user_id"`
	UserID            uint      `gorm:"index" json:"user_id"`
	PlanID            uint      `gorm:"index" json:"plan_id"`
	CouponID          *uint     `gorm:"index" json:"coupon_id"`
	PaymentID         *uint     `gorm:"index" json:"payment_id"`
	Type              int       `json:"type"` // 1: new, 2: renew, 3: upgrade, 4: reset
	Period            string    `gorm:"size:20" json:"period"`
	TradeNo           string    `gorm:"size:36;uniqueIndex" json:"trade_no"`
	CallbackNo        *string   `gorm:"size:255" json:"callback_no"`
	TotalAmount       int64     `json:"total_amount"`
	DiscountAmount    *int64    `json:"discount_amount"`
	SurplusAmount     *int64    `json:"surplus_amount"`
	RefundAmount      *int64    `json:"refund_amount"`
	Balance           *int64    `json:"balance"`
	SurplusOrder      *string   `gorm:"type:text" json:"surplus_order"`
	Status            int       `gorm:"default:0" json:"status"` // 0: pending, 1: paid, 2: cancelled, 3: completed, 4: discounted
	CommissionStatus  int       `gorm:"default:0" json:"commission_status"`
	CommissionBalance int64     `gorm:"default:0" json:"commission_balance"`
	PaidAt            *int64    `json:"paid_at"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`

	// Relations
	User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
	Plan *Plan `gorm:"foreignKey:PlanID" json:"plan,omitempty"`
}

Order 订单模型

func (Order) TableName

func (Order) TableName() string

type ParsedNode

type ParsedNode struct {
	ID     string `json:"id"`     // 唯一标识 (hash)
	Name   string `json:"name"`   // 节点名称
	Type   string `json:"type"`   // 协议类型: vless, vmess, trojan, shadowsocks, hysteria2, tuic, anytls, wireguard
	Server string `json:"server"` // 服务器地址 (host)
	Port   int    `json:"port"`   // 服务器端口 (server_port)

	// 认证信息 (渲染后填入)
	UUID     string `json:"uuid,omitempty"`     // VMess/VLESS UUID (用户ID)
	Password string `json:"password,omitempty"` // Trojan/SS 密码

	// TLS 配置 (tls: 0=None, 1=TLS, 2=Reality)
	TLSMode        int    `json:"tls_mode"`                   // TLS 模式: 0=无, 1=TLS, 2=Reality
	TLS            bool   `json:"tls"`                        // 是否启用 TLS (兼容字段)
	TLSFingerprint string `json:"tls_fingerprint,omitempty"`  // TLS 指纹 (fp)
	SkipCertVerify bool   `json:"skip_cert_verify,omitempty"` // 跳过证书验证
	ServerName     string `json:"server_name,omitempty"`      // SNI 服务器名称
	ALPN           string `json:"alpn,omitempty"`             // ALPN 设置

	// Reality 配置 (当 TLSMode=2 时使用)
	RealityPublicKey string `json:"reality_public_key,omitempty"` // Reality 公钥 (pbk)
	RealityShortID   string `json:"reality_short_id,omitempty"`   // Reality ShortId (sid)
	RealitySpiderX   string `json:"reality_spider_x,omitempty"`   // Reality SpiderX (spx)

	// VLESS 特有配置
	Flow       string `json:"flow,omitempty"`       // VLESS 流控: xtls-rprx-vision
	Encryption string `json:"encryption,omitempty"` // VLESS 加密: 空 或 mlkem768x25519plus

	// VLESS Encryption Settings (当 Encryption 非空时)
	EncryptionSettings *EncryptionSettings `json:"encryption_settings,omitempty"`

	// Shadowsocks 配置
	Cipher    string `json:"cipher,omitempty"`     // SS 加密方式
	ServerKey string `json:"server_key,omitempty"` // SS2022 服务器密钥

	// WireGuard 配置
	PrivateKey   string   `json:"private_key,omitempty"`
	PublicKey    string   `json:"public_key,omitempty"`
	PresharedKey string   `json:"preshared_key,omitempty"`
	PeerIP       string   `json:"peer_ip,omitempty"`
	AllowedIPs   []string `json:"allowed_ips,omitempty"`
	DNS          []string `json:"dns,omitempty"`
	MTU          int      `json:"mtu,omitempty"`

	// 传输层配置 (network)
	Transport         string         `json:"transport,omitempty"`          // 传输协议: tcp, ws, grpc, httpupgrade, xhttp
	TransportSettings map[string]any `json:"transport_settings,omitempty"` // 传输层配置

	// 协议特定配置 (兼容旧字段)
	Settings map[string]any `json:"settings,omitempty"`

	// 来源信息
	SourceType string `json:"source_type"` // template, node, external
	SourceID   uint   `json:"source_id"`   // 来源 ID
	SourceName string `json:"source_name"` // 来源名称
	GroupID    uint   `json:"group_id"`    // 所属分组
	GroupName  string `json:"group_name"`  // 分组名称
}

ParsedNode 解析后的统一节点格式 符合 AnixOps Agent/Xray 协议配置规范

func (*ParsedNode) IsValid

func (n *ParsedNode) IsValid() bool

IsValid checks whether a parsed node has all required fields populated.

type PayPalConfig

type PayPalConfig struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	WebhookID    string `json:"webhook_id"`
	SandboxMode  bool   `json:"sandbox_mode"`
	Currency     string `json:"currency"`
}

PayPalConfig PayPal 支付配置

type Payment

type Payment struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"size:100" json:"name"`    // 支付名称
	Icon      *string   `gorm:"size:255" json:"icon"`    // 支付图标
	Method    string    `gorm:"size:20" json:"method"`   // crypto 或 fiat
	Provider  string    `gorm:"size:50" json:"provider"` // x402, stripe, paypal 等
	Config    string    `gorm:"type:text" json:"config"` // JSON 配置
	Notify    *string   `gorm:"size:255" json:"notify"`  // 回调地址
	Sort      int       `gorm:"default:0" json:"sort"`   // 排序
	Enable    int       `gorm:"default:1" json:"enable"` // 是否启用
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Payment 支付配置模型

func (Payment) TableName

func (Payment) TableName() string

type PaymentChannel

type PaymentChannel struct {
	ID          uint    `json:"id"`
	Name        string  `json:"name"`
	Type        string  `json:"type"`
	Icon        string  `json:"icon"`
	MinAmount   float64 `json:"min_amount"`
	MaxAmount   float64 `json:"max_amount"`
	FeeRate     float64 `json:"fee_rate"`
	FeeFixed    float64 `json:"fee_fixed"`
	Description string  `json:"description"`
}

PaymentChannel 支付渠道 (用于前端显示)

type PaymentGateway

type PaymentGateway struct {
	ID      uint   `gorm:"primaryKey" json:"id"`
	Name    string `gorm:"size:100;not null" json:"name"`
	Type    string `gorm:"size:20;not null" json:"type"` // alipay/wechat/stripe/usdt/epay
	Enabled bool   `gorm:"default:false" json:"enabled"`
	Icon    string `gorm:"size:255" json:"icon"` // 图标URL

	// 配置 (JSON格式存储不同支付方式的配置)
	Config string `gorm:"type:text" json:"config"`

	// 费率设置
	FeeRate  float64 `gorm:"default:0" json:"fee_rate"`  // 手续费率 (0-1)
	FeeFixed float64 `gorm:"default:0" json:"fee_fixed"` // 固定手续费

	// 限额设置
	MinAmount float64 `gorm:"default:1" json:"min_amount"`     // 最小金额
	MaxAmount float64 `gorm:"default:10000" json:"max_amount"` // 最大金额

	// 显示设置
	Sort        int    `gorm:"default:0" json:"sort"`       // 排序
	Description string `gorm:"size:500" json:"description"` // 说明文字

	// 统计
	TotalOrders int64   `json:"total_orders"`
	TotalAmount float64 `json:"total_amount"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

PaymentGateway 支付网关配置 (扩展现有Payment模型)

func (PaymentGateway) TableName

func (PaymentGateway) TableName() string

TableName 指定表名

type PaymentLog

type PaymentLog struct {
	ID            uint      `gorm:"primaryKey" json:"id"`
	OrderID       uint      `gorm:"index" json:"order_id"`
	PaymentID     uint      `gorm:"index" json:"payment_id"`
	TradeNo       string    `gorm:"size:64;index" json:"trade_no"`  // 内部交易号
	CallbackNo    *string   `gorm:"size:255" json:"callback_no"`    // 外部交易号
	Method        string    `gorm:"size:20" json:"method"`          // crypto 或 fiat
	Provider      string    `gorm:"size:50" json:"provider"`        // 支付提供商
	Amount        int64     `json:"amount"`                         // 支付金额 (分)
	Currency      string    `gorm:"size:10" json:"currency"`        // 货币类型 (USD, CNY, ETH, USDT等)
	Status        int       `gorm:"default:0" json:"status"`        // 支付状态
	RawData       *string   `gorm:"type:text" json:"raw_data"`      // 原始回调数据
	TxHash        *string   `gorm:"size:255" json:"tx_hash"`        // 区块链交易哈希 (仅虚拟货币)
	WalletAddress *string   `gorm:"size:255" json:"wallet_address"` // 钱包地址 (仅虚拟货币)
	Network       *string   `gorm:"size:50" json:"network"`         // 区块链网络 (仅虚拟货币)
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

PaymentLog 支付日志

func (PaymentLog) TableName

func (PaymentLog) TableName() string

type PaymentRecord

type PaymentRecord struct {
	ID             uint   `gorm:"primaryKey" json:"id"`
	TradeNo        string `gorm:"size:64;uniqueIndex" json:"trade_no"` // 商户订单号
	GatewayID      uint   `json:"gateway_id"`                          // 支付网关ID
	GatewayType    string `json:"gateway_type"`                        // 支付类型
	GatewayTradeNo string `gorm:"size:100" json:"gateway_trade_no"`    // 第三方订单号
	Provider       string `gorm:"size:50" json:"provider"`             // 支付提供商 (x402/stripe/paypal 等)
	UserID         uint   `json:"user_id"`

	// 金额信息
	Amount       float64 `json:"amount"`                                // 订单金额
	FeeAmount    float64 `json:"fee_amount"`                            // 手续费
	ActualAmount float64 `json:"actual_amount"`                         // 实际支付金额
	Currency     string  `gorm:"size:10;default:'CNY'" json:"currency"` // 货币类型

	// 状态 (复用 PaymentStatus 常量)
	Status      int        `json:"status"` // 0=待支付 1=已支付 2=已取消 3=已退款
	PaidAt      *time.Time `json:"paid_at"`
	CancelledAt *time.Time `json:"cancelled_at"`
	RefundedAt  *time.Time `json:"refunded_at"`

	// 回调信息
	NotifyData string `gorm:"type:text" json:"notify_data"` // 回调原始数据
	ClientIP   string `gorm:"size:50" json:"client_ip"`

	// 区块链相关 (虚拟货币支付)
	TxHash        *string `gorm:"size:255" json:"tx_hash"`        // 区块链交易哈希
	WalletAddress *string `gorm:"size:255" json:"wallet_address"` // 钱包地址
	Network       *string `gorm:"size:50" json:"network"`         // 区块链网络

	// 关联
	OrderID *uint `json:"order_id"` // 关联订单

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

PaymentRecord 支付记录

func (PaymentRecord) TableName

func (PaymentRecord) TableName() string

TableName 指定表名

type Plan

type Plan struct {
	ID                 uint    `gorm:"primaryKey" json:"id"`
	GroupID            uint    `gorm:"index" json:"group_id"`
	TransferEnable     int64   `json:"transfer_enable"` // GB
	SpeedLimit         *int64  `json:"speed_limit"`
	DeviceLimit        *int    `json:"device_limit"`
	Name               string  `gorm:"size:255" json:"name"`
	Content            *string `gorm:"type:text" json:"content"`
	Show               int     `gorm:"default:0" json:"show"`
	Sort               *int    `json:"sort"`
	Renew              int     `gorm:"default:1" json:"renew"`
	ResetPrice         *int64  `json:"reset_price"`
	ResetTrafficMethod *int    `json:"reset_traffic_method"`
	CapacityLimit      *int    `json:"capacity_limit"`

	// Prices
	MonthPrice     *int64 `json:"month_price"`
	QuarterPrice   *int64 `json:"quarter_price"`
	HalfYearPrice  *int64 `json:"half_year_price"`
	YearPrice      *int64 `json:"year_price"`
	TwoYearPrice   *int64 `json:"two_year_price"`
	ThreeYearPrice *int64 `json:"three_year_price"`
	OnetimePrice   *int64 `json:"onetime_price"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Plan 订阅计划模型

func (*Plan) GetDeviceLimit

func (p *Plan) GetDeviceLimit() int

GetDeviceLimit 获取设备限制

func (*Plan) GetSpeedLimit

func (p *Plan) GetSpeedLimit() int64

GetSpeedLimit 获取速度限制

func (Plan) TableName

func (Plan) TableName() string

type PlanSubscriptionGroup

type PlanSubscriptionGroup struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	PlanID    uint      `gorm:"uniqueIndex:idx_plan_group" json:"plan_id"`
	GroupID   uint      `gorm:"uniqueIndex:idx_plan_group" json:"group_id"`
	CreatedAt time.Time `json:"created_at"`

	// 关联
	Plan  *Plan              `gorm:"foreignKey:PlanID" json:"plan,omitempty"`
	Group *SubscriptionGroup `gorm:"foreignKey:GroupID" json:"group,omitempty"`
}

PlanSubscriptionGroup 套餐-订阅分组关联 购买某个套餐自动获得对应分组权限

func (PlanSubscriptionGroup) TableName

func (PlanSubscriptionGroup) TableName() string

type Plugin

type Plugin struct {
	ID          string    `gorm:"primaryKey;size:120" json:"id"`
	Name        string    `gorm:"size:160;not null" json:"name"`
	Description string    `gorm:"type:text" json:"description"`
	Publisher   string    `gorm:"size:120;not null" json:"publisher"`
	Official    bool      `gorm:"not null;default:false" json:"official"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func (Plugin) TableName

func (Plugin) TableName() string

type PluginArtifact

type PluginArtifact struct {
	ID             uint      `gorm:"primaryKey" json:"id"`
	ReleaseID      uint      `gorm:"not null;uniqueIndex" json:"release_id"`
	PluginID       string    `gorm:"size:120;not null;index;uniqueIndex:ux_plugin_artifact_key" json:"plugin_id"`
	Version        string    `gorm:"size:64;not null;uniqueIndex:ux_plugin_artifact_key" json:"version"`
	ArtifactSHA256 string    `gorm:"size:64;not null;uniqueIndex:ux_plugin_artifact_key" json:"artifact_sha256"`
	SizeBytes      int64     `gorm:"not null" json:"size_bytes"`
	StorageKey     string    `gorm:"size:320;not null;uniqueIndex" json:"storage_key"`
	Data           []byte    `json:"-"`
	CreatedAt      time.Time `json:"created_at"`
}

func (PluginArtifact) TableName

func (PluginArtifact) TableName() string

type PluginConfiguration

type PluginConfiguration struct {
	InstallationID uint      `gorm:"primaryKey" json:"installation_id"`
	Revision       int64     `gorm:"not null;default:0" json:"revision"`
	ConfigJSON     string    `gorm:"type:text;not null;default:{}" json:"config"`
	ConfigHash     string    `gorm:"size:64;not null" json:"config_hash"`
	UpdatedBy      uint      `gorm:"not null" json:"updated_by"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

PluginConfiguration is the kernel-owned, revisioned configuration document for one installation. Plugin packages receive a copy through an operation; they never write the shared configuration table directly.

func (PluginConfiguration) TableName

func (PluginConfiguration) TableName() string

type PluginInstallation

type PluginInstallation struct {
	ID                  uint       `gorm:"primaryKey" json:"id"`
	PluginID            string     `gorm:"size:120;not null;uniqueIndex:ux_plugin_install_target" json:"plugin_id"`
	Target              string     `gorm:"size:20;not null;uniqueIndex:ux_plugin_install_target" json:"target"`
	DesiredVersion      string     `gorm:"size:64;not null" json:"desired_version"`
	ObservedVersion     string     `gorm:"size:64" json:"observed_version"`
	PreviousVersion     string     `gorm:"size:64" json:"previous_version"`
	State               string     `gorm:"size:32;not null;index" json:"state"`
	Enabled             bool       `gorm:"not null;default:false" json:"enabled"`
	LifecycleGeneration int64      `gorm:"not null;default:0" json:"lifecycle_generation"`
	ConfigRevision      int64      `gorm:"not null;default:0" json:"config_revision"`
	LastError           string     `gorm:"type:text" json:"last_error"`
	CreatedAt           time.Time  `json:"created_at"`
	UpdatedAt           time.Time  `json:"updated_at"`
	DisabledAt          *time.Time `json:"disabled_at"`
}

func (PluginInstallation) TableName

func (PluginInstallation) TableName() string

type PluginLifecyclePlan

type PluginLifecyclePlan struct {
	ID              string     `gorm:"primaryKey;size:64" json:"id"`
	IdempotencyKey  string     `gorm:"size:160;not null;uniqueIndex" json:"idempotency_key"`
	Target          string     `gorm:"size:20;not null;index" json:"target"`
	RootPluginID    string     `gorm:"size:120;not null;index" json:"root_plugin_id"`
	RootOperationID string     `gorm:"size:64;not null;uniqueIndex" json:"root_operation_id"`
	State           string     `gorm:"size:32;not null;index" json:"state"`
	Outcome         string     `gorm:"size:32" json:"outcome"`
	LastError       string     `gorm:"type:text" json:"last_error"`
	CreatedAt       time.Time  `json:"created_at"`
	UpdatedAt       time.Time  `json:"updated_at"`
	CompletedAt     *time.Time `json:"completed_at"`
}

PluginLifecyclePlan is the durable Control-side transaction boundary for a dependency closure. Individual KernelOperations remain independently observable and cancellable, while the plan supplies dependency ordering and reverse rollback after a failed or cancelled apply phase.

func (PluginLifecyclePlan) TableName

func (PluginLifecyclePlan) TableName() string

type PluginLifecyclePlanStep

type PluginLifecyclePlanStep struct {
	ID                      uint       `gorm:"primaryKey" json:"id"`
	PlanID                  string     `gorm:"size:64;not null;uniqueIndex:ux_plugin_lifecycle_plan_step" json:"plan_id"`
	Sequence                int        `gorm:"not null;uniqueIndex:ux_plugin_lifecycle_plan_step;index" json:"sequence"`
	PluginID                string     `gorm:"size:120;not null;index" json:"plugin_id"`
	TargetVersion           string     `gorm:"size:64;not null" json:"target_version"`
	HadInstallation         bool       `gorm:"not null" json:"had_installation"`
	PreviousDesiredVersion  string     `gorm:"size:64" json:"previous_desired_version"`
	PreviousObservedVersion string     `gorm:"size:64" json:"previous_observed_version"`
	PreviousPreviousVersion string     `gorm:"size:64" json:"previous_previous_version"`
	PreviousState           string     `gorm:"size:32" json:"previous_state"`
	PreviousEnabled         bool       `gorm:"not null" json:"previous_enabled"`
	PreviousDisabledAt      *time.Time `json:"previous_disabled_at"`
	PreviousLastError       string     `gorm:"type:text" json:"previous_last_error"`
	Changed                 bool       `gorm:"not null" json:"changed"`
	ApplyState              string     `gorm:"size:32;not null;default:pending;index" json:"apply_state"`
	RollbackState           string     `gorm:"size:32;not null;default:pending;index" json:"rollback_state"`
	CreatedAt               time.Time  `json:"created_at"`
	UpdatedAt               time.Time  `json:"updated_at"`
}

PluginLifecyclePlanStep stores the old desired state separately from the runtime operation. That lets a restarted worker restore intent precisely after a dependency graph failure without deleting package data.

func (PluginLifecyclePlanStep) TableName

func (PluginLifecyclePlanStep) TableName() string

type PluginRelease

type PluginRelease struct {
	ID                   uint      `gorm:"primaryKey" json:"id"`
	PluginID             string    `gorm:"size:120;not null;uniqueIndex:ux_plugin_release" json:"plugin_id"`
	Version              string    `gorm:"size:64;not null;uniqueIndex:ux_plugin_release" json:"version"`
	APIVersion           string    `gorm:"size:32;not null" json:"api_version"`
	ManifestJSON         string    `gorm:"type:text;not null" json:"manifest"`
	ArtifactSHA256       string    `gorm:"size:64;not null" json:"artifact_sha256"`
	Signature            string    `gorm:"type:text;not null" json:"signature"`
	TrustRootFingerprint string    `gorm:"size:64;index" json:"trust_root_fingerprint"`
	TrustRootKeyID       string    `gorm:"size:32;index" json:"trust_root_key_id"`
	PublishedAt          time.Time `json:"published_at"`
	CreatedAt            time.Time `json:"created_at"`
}

func (PluginRelease) TableName

func (PluginRelease) TableName() string

type PluginTargetLock

type PluginTargetLock struct {
	Target    string    `gorm:"primaryKey;size:20" json:"target"`
	UpdatedAt time.Time `json:"updated_at"`
}

PluginTargetLock serializes dependency/conflict validation and installation intent changes for one runtime target across concurrent Control processes.

func (PluginTargetLock) TableName

func (PluginTargetLock) TableName() string

type PluginTelemetryState

type PluginTelemetryState struct {
	NodeID      uint      `gorm:"primaryKey" json:"node_id"`
	PluginID    string    `gorm:"primaryKey;size:120" json:"plugin_id"`
	MetricsJSON string    `gorm:"type:text;not null" json:"metrics"`
	ObservedAt  time.Time `gorm:"not null;index" json:"observed_at"`
	ReceivedAt  time.Time `gorm:"not null;index" json:"received_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

PluginTelemetryState stores the latest scalar snapshot received from one enabled Agent plugin. Metrics are namespaced by plugin at the transport boundary and persisted as JSON so the kernel does not need to know every plugin-specific field in advance.

func (PluginTelemetryState) TableName

func (PluginTelemetryState) TableName() string

type PluginTrustRoot

type PluginTrustRoot struct {
	Fingerprint string     `gorm:"primaryKey;size:64" json:"fingerprint"`
	KeyID       string     `gorm:"size:32;not null;index" json:"key_id"`
	PublicKey   string     `gorm:"type:text;not null" json:"public_key"`
	Publisher   string     `gorm:"size:120;not null;index" json:"publisher"`
	Active      bool       `gorm:"not null;default:true;index" json:"active"`
	CreatedAt   time.Time  `json:"created_at"`
	LastSeenAt  time.Time  `json:"last_seen_at"`
	RetiredAt   *time.Time `json:"retired_at"`
}

func (PluginTrustRoot) TableName

func (PluginTrustRoot) TableName() string

type PluginWebUIAsset

type PluginWebUIAsset struct {
	ID           uint      `gorm:"primaryKey" json:"id"`
	ReleaseID    uint      `gorm:"not null;uniqueIndex" json:"release_id"`
	PluginID     string    `gorm:"size:120;not null;index;uniqueIndex:ux_plugin_webui_asset_addr" json:"plugin_id"`
	Version      string    `gorm:"size:64;not null;uniqueIndex:ux_plugin_webui_asset_addr" json:"version"`
	BundlePath   string    `gorm:"size:240;not null" json:"bundle_path"`
	BundleSHA256 string    `gorm:"size:64;not null;index;uniqueIndex:ux_plugin_webui_asset_addr" json:"bundle_sha256"`
	SizeBytes    int64     `gorm:"not null" json:"size_bytes"`
	ContentType  string    `gorm:"size:120;not null" json:"content_type"`
	StorageKey   string    `gorm:"size:360;not null;uniqueIndex" json:"storage_key"`
	Data         []byte    `json:"-"`
	CreatedAt    time.Time `json:"created_at"`
}

func (PluginWebUIAsset) TableName

func (PluginWebUIAsset) TableName() string

type ProtocolTemplate

type ProtocolTemplate struct {
	Type        ProtocolType `json:"type"`
	Name        string       `json:"name"`
	Description string       `json:"description"`
	DefaultPort int          `json:"default_port"`
	Settings    string       `json:"settings"`         // 默认配置JSON
	TLS         int          `json:"tls"`              // 0=无, 1=TLS, 2=Reality
	TLSSettings string       `json:"tls_settings"`     // TLS配置JSON
	Transport   string       `json:"transport"`        // tcp, ws, etc.
	Reality     string       `json:"reality_settings"` // Reality配置JSON
}

ProtocolTemplate 协议模板 (快速添加)

func GetProtocolTemplates

func GetProtocolTemplates() []ProtocolTemplate

GetProtocolTemplates 获取协议模板列表

type ProtocolType

type ProtocolType string

ProtocolType 协议类型

const (
	ProtocolVMess       ProtocolType = "vmess"
	ProtocolVLESS       ProtocolType = "vless"
	ProtocolTrojan      ProtocolType = "trojan"
	ProtocolShadowsocks ProtocolType = "shadowsocks"
	ProtocolHysteria2   ProtocolType = "hysteria2"
	ProtocolTUIC        ProtocolType = "tuic"
	ProtocolAnyTLS      ProtocolType = "anytls"
	ProtocolWireGuard   ProtocolType = "wireguard"
)

type QuotaPolicy

type QuotaPolicy struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	GroupID    uint      `gorm:"not null;index;uniqueIndex:ux_quota_group_key" json:"group_id"`
	Key        string    `gorm:"size:80;not null;uniqueIndex:ux_quota_group_key" json:"key"`
	PolicyJSON string    `gorm:"type:text;not null" json:"policy"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

func (QuotaPolicy) TableName

func (QuotaPolicy) TableName() string

type RegisterRequest

type RegisterRequest struct {
	Email      string `json:"email" binding:"required,email"`
	Password   string `json:"password" binding:"required,min=6"`
	InviteCode string `json:"invite_code"`
}

RegisterRequest 注册请求

type ResourceGrant

type ResourceGrant struct {
	ID           uint      `gorm:"primaryKey" json:"id"`
	GroupID      uint      `gorm:"not null;index;uniqueIndex:ux_resource_grant" json:"group_id"`
	ResourceType string    `gorm:"size:64;not null;uniqueIndex:ux_resource_grant" json:"resource_type"`
	ResourceID   string    `gorm:"size:160;not null;uniqueIndex:ux_resource_grant" json:"resource_id"`
	Permissions  string    `gorm:"type:text;not null" json:"permissions"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

func (ResourceGrant) TableName

func (ResourceGrant) TableName() string

type ServerAnyTLS

type ServerAnyTLS struct {
	BaseServer
	PaddingScheme *string `gorm:"type:text" json:"padding_scheme"` // JSON array
	ServerName    *string `gorm:"size:255" json:"server_name"`
}

ServerAnyTLS AnyTLS服务器

func (*ServerAnyTLS) GetHost

func (s *ServerAnyTLS) GetHost() string

func (*ServerAnyTLS) GetID

func (s *ServerAnyTLS) GetID() uint

func (*ServerAnyTLS) GetPort

func (s *ServerAnyTLS) GetPort() int

func (*ServerAnyTLS) GetServerPort

func (s *ServerAnyTLS) GetServerPort() int

func (*ServerAnyTLS) GetType

func (s *ServerAnyTLS) GetType() ServerType

func (ServerAnyTLS) TableName

func (ServerAnyTLS) TableName() string

type ServerGroup

type ServerGroup struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"size:255" json:"name"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ServerGroup 服务器分组

func (ServerGroup) TableName

func (ServerGroup) TableName() string

type ServerHysteria

type ServerHysteria struct {
	BaseServer
	Version               int     `gorm:"default:2" json:"version"` // 1 or 2
	UpMbps                int     `json:"up_mbps"`
	DownMbps              int     `json:"down_mbps"`
	Obfs                  string  `gorm:"size:50" json:"obfs"`
	ObfsPassword          *string `gorm:"size:255" json:"obfs_password"`
	ServerName            *string `gorm:"size:255" json:"server_name"`
	IgnoreClientBandwidth int     `gorm:"default:0" json:"ignore_client_bandwidth"`
}

ServerHysteria Hysteria服务器

func (*ServerHysteria) GetHost

func (s *ServerHysteria) GetHost() string

func (*ServerHysteria) GetID

func (s *ServerHysteria) GetID() uint

func (*ServerHysteria) GetPort

func (s *ServerHysteria) GetPort() int

func (*ServerHysteria) GetServerPort

func (s *ServerHysteria) GetServerPort() int

func (*ServerHysteria) GetType

func (s *ServerHysteria) GetType() ServerType

func (ServerHysteria) TableName

func (ServerHysteria) TableName() string

type ServerInfo

type ServerInfo interface {
	GetID() uint
	GetType() ServerType
	GetHost() string
	GetPort() int
	GetServerPort() int
	GetGroupIDs() []uint
	GetRouteIDs() []uint
}

ServerInfo 统一服务器信息接口

type ServerRoute

type ServerRoute struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	Remarks     string    `gorm:"size:255" json:"remarks"`
	Match       string    `gorm:"type:text" json:"match"`
	Action      string    `gorm:"size:20" json:"action"` // block, dns
	ActionValue *string   `gorm:"type:text" json:"action_value"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

ServerRoute 服务器路由

func (ServerRoute) TableName

func (ServerRoute) TableName() string

type ServerShadowsocks

type ServerShadowsocks struct {
	BaseServer
	Cipher       string  `gorm:"size:50" json:"cipher"`
	ServerKey    *string `gorm:"size:255" json:"server_key"`
	Obfs         *string `gorm:"size:20" json:"obfs"`
	ObfsSettings *string `gorm:"type:text" json:"obfs_settings"`
}

ServerShadowsocks Shadowsocks服务器

func (*ServerShadowsocks) GetHost

func (s *ServerShadowsocks) GetHost() string

func (*ServerShadowsocks) GetID

func (s *ServerShadowsocks) GetID() uint

func (*ServerShadowsocks) GetPort

func (s *ServerShadowsocks) GetPort() int

func (*ServerShadowsocks) GetServerPort

func (s *ServerShadowsocks) GetServerPort() int

func (*ServerShadowsocks) GetType

func (s *ServerShadowsocks) GetType() ServerType

func (ServerShadowsocks) TableName

func (ServerShadowsocks) TableName() string

type ServerTUIC

type ServerTUIC struct {
	BaseServer
	CongestionControl string  `gorm:"size:20;default:bbr" json:"congestion_control"` // bbr, cubic, new_reno
	ZeroRTTHandshake  int     `gorm:"default:0" json:"zero_rtt_handshake"`
	ServerName        *string `gorm:"size:255" json:"server_name"`
}

ServerTUIC TUIC服务器

func (*ServerTUIC) GetHost

func (s *ServerTUIC) GetHost() string

func (*ServerTUIC) GetID

func (s *ServerTUIC) GetID() uint

func (*ServerTUIC) GetPort

func (s *ServerTUIC) GetPort() int

func (*ServerTUIC) GetServerPort

func (s *ServerTUIC) GetServerPort() int

func (*ServerTUIC) GetType

func (s *ServerTUIC) GetType() ServerType

func (ServerTUIC) TableName

func (ServerTUIC) TableName() string

type ServerTrojan

type ServerTrojan struct {
	BaseServer
	Network         string  `gorm:"size:20" json:"network"`
	NetworkSettings *string `gorm:"type:text" json:"network_settings"`
	ServerName      *string `gorm:"size:255" json:"server_name"`
	AllowInsecure   int     `gorm:"default:0" json:"allow_insecure"`
}

ServerTrojan Trojan服务器

func (*ServerTrojan) GetHost

func (s *ServerTrojan) GetHost() string

func (*ServerTrojan) GetID

func (s *ServerTrojan) GetID() uint

func (*ServerTrojan) GetPort

func (s *ServerTrojan) GetPort() int

func (*ServerTrojan) GetServerPort

func (s *ServerTrojan) GetServerPort() int

func (*ServerTrojan) GetType

func (s *ServerTrojan) GetType() ServerType

func (ServerTrojan) TableName

func (ServerTrojan) TableName() string

type ServerType

type ServerType string

ServerType 服务器类型

const (
	ServerTypeVMess       ServerType = "vmess"
	ServerTypeVLESS       ServerType = "vless"
	ServerTypeTrojan      ServerType = "trojan"
	ServerTypeShadowsocks ServerType = "shadowsocks"
	ServerTypeHysteria    ServerType = "hysteria"
	ServerTypeHysteria2   ServerType = "hysteria2"
	ServerTypeTUIC        ServerType = "tuic"
	ServerTypeAnyTLS      ServerType = "anytls"
)

type ServerVLESS

type ServerVLESS struct {
	BaseServer
	Network            string  `gorm:"size:20" json:"network"`
	NetworkSettings    *string `gorm:"type:text" json:"network_settings"`
	Flow               string  `gorm:"size:50" json:"flow"` // xtls-rprx-vision
	Encryption         *string `gorm:"size:50" json:"encryption"`
	EncryptionSettings *string `gorm:"type:text" json:"encryption_settings"`
	RealitySettings    *string `gorm:"type:text" json:"reality_settings"`
}

ServerVLESS VLESS服务器

func (*ServerVLESS) GetHost

func (s *ServerVLESS) GetHost() string

func (*ServerVLESS) GetID

func (s *ServerVLESS) GetID() uint

func (*ServerVLESS) GetPort

func (s *ServerVLESS) GetPort() int

func (*ServerVLESS) GetServerPort

func (s *ServerVLESS) GetServerPort() int

func (*ServerVLESS) GetType

func (s *ServerVLESS) GetType() ServerType

func (ServerVLESS) TableName

func (ServerVLESS) TableName() string

type ServerVMess

type ServerVMess struct {
	BaseServer
	Network         string  `gorm:"size:20" json:"network"` // tcp, ws, grpc, http, quic
	NetworkSettings *string `gorm:"type:text" json:"network_settings"`
}

ServerVMess VMess服务器

func (*ServerVMess) GetHost

func (s *ServerVMess) GetHost() string

func (*ServerVMess) GetID

func (s *ServerVMess) GetID() uint

func (*ServerVMess) GetPort

func (s *ServerVMess) GetPort() int

func (*ServerVMess) GetServerPort

func (s *ServerVMess) GetServerPort() int

func (*ServerVMess) GetType

func (s *ServerVMess) GetType() ServerType

func (ServerVMess) TableName

func (ServerVMess) TableName() string

type ServiceScope

type ServiceScope struct {
	ID          string    `gorm:"primaryKey;size:64" json:"id"`
	Name        string    `gorm:"size:120;not null" json:"name"`
	Description string    `gorm:"type:text" json:"description"`
	PluginID    string    `gorm:"size:120;index" json:"plugin_id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

ServiceScope is an authorization namespace. A user may belong to multiple groups in each scope without leaking quota or grants into another service.

func (ServiceScope) TableName

func (ServiceScope) TableName() string

type SpeedLimit

type SpeedLimit struct {
	ID          uint   `gorm:"primaryKey" json:"id"`
	CreatedTime int64  `gorm:"index;not null" json:"createdTime"`
	UpdatedTime int64  `gorm:"index;not null" json:"updatedTime"`
	Status      int    `gorm:"default:1" json:"status"`
	Name        string `gorm:"size:100;not null" json:"name"`
	Speed       int64  `gorm:"not null" json:"speed"`
	TunnelID    uint   `gorm:"index;not null" json:"tunnelId"`
	TunnelName  string `gorm:"size:100;not null" json:"tunnelName"`
}

SpeedLimit mirrors the flux-panel speed-limit resource.

func (SpeedLimit) TableName

func (SpeedLimit) TableName() string

type StatServer

type StatServer struct {
	ID         uint   `gorm:"primaryKey" json:"id"`
	ServerID   uint   `gorm:"index" json:"server_id"`
	ServerType string `gorm:"size:20" json:"server_type"`
	U          int64  `json:"u"`
	D          int64  `json:"d"`
	RecordType string `gorm:"size:1" json:"record_type"` // d: day, m: month
	RecordAt   int64  `gorm:"index" json:"record_at"`
}

StatServer 服务器统计

func (StatServer) TableName

func (StatServer) TableName() string

type StatUser

type StatUser struct {
	ID         uint    `gorm:"primaryKey" json:"id"`
	UserID     uint    `gorm:"index" json:"user_id"`
	ServerRate float64 `json:"server_rate"`
	U          int64   `json:"u"`
	D          int64   `json:"d"`
	RecordType string  `gorm:"size:1" json:"record_type"`
	RecordAt   int64   `gorm:"index" json:"record_at"`
}

StatUser 用户统计

func (StatUser) TableName

func (StatUser) TableName() string

type StripeConfig

type StripeConfig struct {
	PublishableKey string `json:"publishable_key"`
	SecretKey      string `json:"secret_key"`
	WebhookSecret  string `json:"webhook_secret"`
	Currency       string `json:"currency"` // USD, EUR 等
}

StripeConfig Stripe 支付配置

type SubscriptionFormat

type SubscriptionFormat string

SubscriptionFormat 订阅格式类型

const (
	FormatV2Ray        SubscriptionFormat = "v2ray"        // Base64 编码的链接列表
	FormatClash        SubscriptionFormat = "clash"        // Clash YAML
	FormatStash        SubscriptionFormat = "stash"        // Stash YAML (兼容 Clash)
	FormatEgern        SubscriptionFormat = "egern"        // Egern YAML (兼容 Clash)
	FormatSurge        SubscriptionFormat = "surge"        // Surge 配置
	FormatLoon         SubscriptionFormat = "loon"         // Loon 配置
	FormatShadowrocket SubscriptionFormat = "shadowrocket" // Shadowrocket 配置
	FormatQuantumultX  SubscriptionFormat = "quantumultx"  // Quantumult X 配置
	FormatJSON         SubscriptionFormat = "json"         // 原始 JSON
	FormatBase64JSON   SubscriptionFormat = "base64json"   // Base64 编码的 JSON (你的自定义格式)
	FormatSingBox      SubscriptionFormat = "sing-box"     // Sing-box JSON
	FormatWireGuard    SubscriptionFormat = "wireguard"    // WireGuard 原生配置
)

type SubscriptionGroup

type SubscriptionGroup struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	Name        string    `gorm:"size:100;uniqueIndex" json:"name"` // 分组名称
	Description *string   `gorm:"size:500" json:"description"`      // 分组描述
	Priority    int       `gorm:"default:0" json:"priority"`        // 优先级 (数值越大优先级越高)
	Enable      int       `gorm:"default:1" json:"enable"`          // 是否启用
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`

	// 关联
	Templates []SubscriptionTemplate `gorm:"foreignKey:GroupID" json:"templates,omitempty"`
	Protocols []NodeProtocol         `gorm:"many2many:v2_subscription_group_node_protocols;" json:"protocols,omitempty"`
}

SubscriptionGroup 订阅分组 (权限组) 不同分组可以看到不同的节点配置

func (SubscriptionGroup) TableName

func (SubscriptionGroup) TableName() string

type SubscriptionRequest

type SubscriptionRequest struct {
	Token           string             `json:"token"`             // 用户 Token
	Format          SubscriptionFormat `json:"format,omitempty"`  // 输出格式
	Groups          []uint             `json:"groups,omitempty"`  // 指定分组 (可选)
	Include         string             `json:"include,omitempty"` // 包含关键词
	Exclude         string             `json:"exclude,omitempty"` // 排除关键词
	SubscribeURL    string             `json:"-"`                 // 当前请求订阅 URL(供格式化器使用)
	SubscribeDomain string             `json:"-"`                 // 当前请求订阅域名(供格式化器使用)
}

SubscriptionRequest 订阅请求参数

type SubscriptionResponse

type SubscriptionResponse struct {
	Content      string `json:"content"`                 // 订阅内容
	ContentType  string `json:"content_type"`            // MIME 类型
	Filename     string `json:"filename,omitempty"`      // 下载文件名
	UpdatedAt    int64  `json:"updated_at"`              // 更新时间
	ExpireAt     int64  `json:"expire_at,omitempty"`     // 用户过期时间
	UsedTraffic  int64  `json:"used_traffic,omitempty"`  // 已用流量
	TotalTraffic int64  `json:"total_traffic,omitempty"` // 总流量
}

SubscriptionResponse 订阅响应

type SubscriptionTemplate

type SubscriptionTemplate struct {
	ID      uint    `gorm:"primaryKey" json:"id"`
	GroupID uint    `gorm:"index" json:"group_id"`   // 所属分组
	Name    string  `gorm:"size:255" json:"name"`    // 模板名称 (显示给用户的节点名)
	Type    string  `gorm:"size:30" json:"type"`     // 协议类型: vmess, vless, trojan, shadowsocks, hysteria2, tuic, anytls
	Enable  int     `gorm:"default:1" json:"enable"` // 是否启用
	Sort    int     `gorm:"default:0" json:"sort"`   // 排序
	Tags    *string `gorm:"size:255" json:"tags"`    // 标签 (JSON array)

	// JSON 模板配置 (高级功能)
	// 支持变量占位符: {{.UUID}}, {{.UserID}}, {{.Email}}, {{.ExpiredAt}}, {{.SpeedLimit}}, {{.DeviceLimit}}
	// 以及自定义变量: {{.Custom.xxx}}
	TemplateJSON string `gorm:"type:text" json:"template_json"`

	// 服务器基础配置 (对应 AnixOps Agent CommonNode)
	Server     string  `gorm:"size:255" json:"server"`      // 服务器地址 (host)
	Port       int     `json:"port"`                        // 端口 (server_port)
	ServerName *string `gorm:"size:255" json:"server_name"` // SNI 服务器名称

	// TLS 配置 (对应 AnixOps Agent tls 字段)
	TLS            int     `gorm:"default:0" json:"tls"`           // 0=无, 1=TLS, 2=Reality
	TLSFingerprint *string `gorm:"size:50" json:"tls_fingerprint"` // TLS 指纹 (chrome, firefox, safari, ios, android, edge, 360, qq, random)
	ALPN           *string `gorm:"size:100" json:"alpn"`           // ALPN (h2,http/1.1)

	// Reality 配置 (当 TLS=2 时使用, 对应 AnixOps Agent tls_settings)
	RealityPublicKey *string `gorm:"size:100" json:"reality_public_key"` // X25519 公钥 (对应 pbk)
	RealityShortID   *string `gorm:"size:50" json:"reality_short_id"`    // Short ID (对应 sid)
	RealitySpiderX   *string `gorm:"size:255" json:"reality_spider_x"`   // SpiderX (对应 spx)
	RealityDest      *string `gorm:"size:255" json:"reality_dest"`       // 回落目标 (dest)

	// 传输层配置 (对应 AnixOps Agent network, network_settings)
	Transport         string  `gorm:"size:20;default:tcp" json:"transport"`          // 传输协议: tcp, ws, grpc, httpupgrade, xhttp
	TransportSettings *string `gorm:"type:text" json:"transport_settings,omitempty"` // 传输层配置 JSON

	// VLESS 特有配置 (对应 AnixOps Agent flow, encryption, encryption_settings)
	Flow               *string `gorm:"size:50" json:"flow"`                  // 流控: xtls-rprx-vision
	Encryption         *string `gorm:"size:50" json:"encryption"`            // 加密: 空 或 mlkem768x25519plus
	EncryptionSettings *string `gorm:"type:text" json:"encryption_settings"` // 加密配置 JSON

	// Shadowsocks 配置 (对应 AnixOps Agent cipher, server_key)
	SSCipher    *string `gorm:"size:50" json:"ss_cipher"`      // SS 加密方式
	SSServerKey *string `gorm:"size:100" json:"ss_server_key"` // SS2022 服务器密钥

	// 协议特定配置 (存储其他不在通用字段中的配置)
	ProtocolSettings *string `gorm:"type:text" json:"protocol_settings"` // 协议配置 JSON

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	// 关联
	Group *SubscriptionGroup `gorm:"foreignKey:GroupID" json:"group,omitempty"`
}

SubscriptionTemplate 订阅模板 (JSON 配置模板) 每个模板定义一种节点配置,通过函数变量赋值后下发给用户 符合 AnixOps Agent/Xray 协议配置规范

func (*SubscriptionTemplate) GetProtocolSettings

func (t *SubscriptionTemplate) GetProtocolSettings() map[string]any

GetProtocolSettings 获取协议配置

func (*SubscriptionTemplate) GetTags

func (t *SubscriptionTemplate) GetTags() []string

GetTags 获取标签列表

func (*SubscriptionTemplate) GetTransportSettings

func (t *SubscriptionTemplate) GetTransportSettings() map[string]any

GetTransportSettings 获取传输层配置

func (SubscriptionTemplate) TableName

func (SubscriptionTemplate) TableName() string

type SystemConfig

type SystemConfig struct {
	ID     uint   `gorm:"primaryKey" json:"id"`
	Key    string `gorm:"size:100;uniqueIndex" json:"key"`
	Value  string `gorm:"type:text" json:"value"`
	Type   string `gorm:"size:20;default:string" json:"type"` // string/number/boolean/json
	Group  string `gorm:"size:50;index" json:"group"`         // 配置分组
	Remark string `gorm:"size:255" json:"remark"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

SystemConfig 系统配置

func (SystemConfig) TableName

func (SystemConfig) TableName() string

TableName 指定表名

type TelegramBot

type TelegramBot struct {
	ID      uint   `gorm:"primaryKey" json:"id"`
	Name    string `gorm:"size:100;not null" json:"name"`
	Token   string `gorm:"size:200;not null" json:"token"`
	Enabled bool   `gorm:"default:false" json:"enabled"`

	// Webhook配置
	WebhookURL string `gorm:"size:255" json:"webhook_url"`
	WebhookSet bool   `gorm:"default:false" json:"webhook_set"`

	// 管理员
	AdminIDs string `gorm:"type:text" json:"admin_ids"` // JSON数组

	// 欢迎消息
	WelcomeMsg string `gorm:"type:text" json:"welcome_msg"`

	// 功能开关
	AllowBind   bool `gorm:"default:true" json:"allow_bind"`   // 允许绑定账户
	AllowSub    bool `gorm:"default:true" json:"allow_sub"`    // 允许获取订阅
	AllowTicket bool `gorm:"default:true" json:"allow_ticket"` // 允许创建工单
	AllowInfo   bool `gorm:"default:true" json:"allow_info"`   // 允许查看信息

	// 统计
	TotalUsers int64 `json:"total_users"`
	TotalChats int64 `json:"total_chats"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

TelegramBot Telegram Bot配置

func (TelegramBot) TableName

func (TelegramBot) TableName() string

TableName 指定表名

type TelegramChat

type TelegramChat struct {
	ID         uint  `gorm:"primaryKey" json:"id"`
	BotID      uint  `gorm:"index" json:"bot_id"`
	TelegramID int64 `gorm:"index" json:"telegram_id"`
	UserID     *uint `json:"user_id"`

	// 消息
	MessageID   int64  `json:"message_id"`
	MessageType string `gorm:"size:20" json:"message_type"` // text/command/callback
	Content     string `gorm:"type:text" json:"content"`

	// 回复
	ReplyToID *uint `json:"reply_to_id"`

	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

TelegramChat Telegram聊天记录

func (TelegramChat) TableName

func (TelegramChat) TableName() string

TableName 指定表名

type TelegramCommand

type TelegramCommand struct {
	ID          uint   `gorm:"primaryKey" json:"id"`
	BotID       uint   `json:"bot_id"`
	Command     string `gorm:"size:50;not null" json:"command"` // 命令 (不含/)
	Description string `gorm:"size:200" json:"description"`     // 描述
	Handler     string `gorm:"size:100" json:"handler"`         // 处理函数名
	Enabled     bool   `gorm:"default:true" json:"enabled"`
	IsAdmin     bool   `gorm:"default:false" json:"is_admin"` // 是否管理员命令
	Sort        int    `gorm:"default:0" json:"sort"`
}

TelegramCommand Bot命令定义

func (TelegramCommand) TableName

func (TelegramCommand) TableName() string

TableName 指定表名

type TelegramNotification

type TelegramNotification struct {
	ID         uint  `gorm:"primaryKey" json:"id"`
	TelegramID int64 `gorm:"index" json:"telegram_id"`
	UserID     *uint `json:"user_id"`

	// 通知内容
	Type    string `gorm:"size:50" json:"type"` // expire/traffic/ticket/system
	Title   string `gorm:"size:200" json:"title"`
	Content string `gorm:"type:text" json:"content"`

	// 状态
	Status int        `json:"status"` // 0=待发送 1=已发送 2=发送失败
	Error  string     `gorm:"size:500" json:"error"`
	SentAt *time.Time `json:"sent_at"`

	CreatedAt time.Time `json:"created_at"`
}

TelegramNotification Telegram通知记录

func (TelegramNotification) TableName

func (TelegramNotification) TableName() string

TableName 指定表名

type TelegramUser

type TelegramUser struct {
	ID           uint   `gorm:"primaryKey" json:"id"`
	UserID       uint   `gorm:"uniqueIndex" json:"user_id"` // 系统用户ID
	User         *User  `gorm:"foreignKey:UserID" json:"user,omitempty"`
	TelegramID   int64  `gorm:"uniqueIndex" json:"telegram_id"` // Telegram用户ID
	Username     string `gorm:"size:100" json:"username"`       // Telegram用户名
	FirstName    string `gorm:"size:100" json:"first_name"`     // 名
	LastName     string `gorm:"size:100" json:"last_name"`      // 姓
	LanguageCode string `gorm:"size:10" json:"language_code"`   // 语言代码

	// 状态
	IsBanned bool       `gorm:"default:false" json:"is_banned"`
	BannedAt *time.Time `json:"banned_at"`

	// 通知设置
	NotifyExpire  bool `gorm:"default:true" json:"notify_expire"`  // 到期通知
	NotifyTraffic bool `gorm:"default:true" json:"notify_traffic"` // 流量通知
	NotifyTicket  bool `gorm:"default:true" json:"notify_ticket"`  // 工单通知

	// 统计
	MessageCount int64     `json:"message_count"`
	LastActive   time.Time `json:"last_active"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

TelegramUser Telegram用户绑定

func (TelegramUser) TableName

func (TelegramUser) TableName() string

TableName 指定表名

type TemplateRenderContext

type TemplateRenderContext struct {
	// 用户信息
	UUID        string `json:"uuid"`
	UserID      uint   `json:"user_id"`
	Email       string `json:"email"`
	ExpiredAt   int64  `json:"expired_at"`
	SpeedLimit  int64  `json:"speed_limit"` // bytes/s
	DeviceLimit int    `json:"device_limit"`

	// 流量信息
	TransferEnable int64 `json:"transfer_enable"` // 总流量
	UsedTraffic    int64 `json:"used_traffic"`    // 已用流量

	// 自定义变量 (管理员可扩展)
	Custom map[string]any `json:"custom,omitempty"`

	// 订阅元信息 (用于生成客户端特定配置,如 Surge managed-config)
	SubscribeURL    string `json:"subscribe_url,omitempty"`
	SubscribeDomain string `json:"subscribe_domain,omitempty"`
}

TemplateRenderContext 模板渲染上下文 传递给模板引擎进行变量替换

type Ticket

type Ticket struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	UserID    uint      `gorm:"index" json:"user_id"`
	Subject   string    `gorm:"size:255" json:"subject"`
	Level     int       `gorm:"default:1" json:"level"`  // 0: low, 1: medium, 2: high
	Status    int       `gorm:"default:0" json:"status"` // 0: open, 1: answered, 2: closed
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	// Relations
	User     *User           `gorm:"foreignKey:UserID" json:"user,omitempty"`
	Messages []TicketMessage `gorm:"foreignKey:TicketID" json:"messages,omitempty"`
}

Ticket 工单模型

func (Ticket) TableName

func (Ticket) TableName() string

type TicketMessage

type TicketMessage struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	TicketID  uint      `gorm:"index" json:"ticket_id"`
	UserID    uint      `gorm:"index" json:"user_id"`
	Message   string    `gorm:"type:text" json:"message"`
	IsAdmin   int       `gorm:"default:0" json:"is_admin"` // 0: user, 1: admin
	CreatedAt time.Time `json:"created_at"`
}

TicketMessage 工单消息模型

func (TicketMessage) TableName

func (TicketMessage) TableName() string

type Topology

type Topology struct {
	ID               uint      `gorm:"primaryKey" json:"id"`
	Name             string    `gorm:"size:160;not null;uniqueIndex" json:"name"`
	ServiceScope     string    `gorm:"size:64;not null;index" json:"service_scope"`
	Description      string    `gorm:"type:text" json:"description"`
	ActiveRevisionID *uint     `gorm:"index" json:"active_revision_id"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

func (Topology) TableName

func (Topology) TableName() string

type TopologyDeployment

type TopologyDeployment struct {
	ID                 uint   `gorm:"primaryKey" json:"id"`
	TopologyID         uint   `gorm:"not null;index" json:"topology_id"`
	RevisionID         uint   `gorm:"not null;index" json:"revision_id"`
	PreviousRevisionID *uint  `json:"previous_revision_id"`
	RolloutGroup       string `gorm:"size:80" json:"rollout_group"`
	State              string `gorm:"size:32;not null;index" json:"state"`
	FailurePolicy      string `gorm:"size:32;not null" json:"failure_policy"`
	LastError          string `gorm:"type:text" json:"last_error"`
	// HealthGateDeadlineAt is a durable grace window for a terminal Agent
	// operation to be followed by its independent runtime observation.
	HealthGateDeadlineAt *time.Time `json:"health_gate_deadline_at"`
	RollbackStartedAt    *time.Time `json:"rollback_started_at"`
	RollbackCompletedAt  *time.Time `json:"rollback_completed_at"`
	CreatedBy            uint       `gorm:"not null" json:"created_by"`
	CreatedAt            time.Time  `json:"created_at"`
	UpdatedAt            time.Time  `json:"updated_at"`
	CompletedAt          *time.Time `json:"completed_at"`
}

func (TopologyDeployment) TableName

func (TopologyDeployment) TableName() string

type TopologyDeploymentStep

type TopologyDeploymentStep struct {
	ID                           uint      `gorm:"primaryKey" json:"id"`
	DeploymentID                 uint      `gorm:"not null;index;uniqueIndex:ux_topology_deployment_step" json:"deployment_id"`
	VertexID                     uint      `gorm:"not null;uniqueIndex:ux_topology_deployment_step" json:"vertex_id"`
	VertexKey                    string    `gorm:"size:120;not null" json:"vertex_key"`
	NodeID                       uint      `gorm:"not null;index" json:"node_id"`
	PluginID                     string    `gorm:"size:120;not null" json:"plugin_id"`
	Role                         string    `gorm:"size:80;not null" json:"role"`
	TargetVersion                string    `gorm:"size:64;not null" json:"target_version"`
	ApplyOrder                   int       `gorm:"not null;index" json:"apply_order"`
	Removal                      bool      `gorm:"not null;default:false" json:"removal"`
	ApplyAction                  string    `gorm:"size:32;not null" json:"apply_action"`
	ConfigJSON                   string    `gorm:"type:text;not null;default:{}" json:"config"`
	RollbackMode                 string    `gorm:"size:32;not null" json:"rollback_mode"`
	RollbackConfigJSON           string    `gorm:"type:text;not null;default:{}" json:"rollback_config"`
	State                        string    `gorm:"size:32;not null;index" json:"state"`
	ConfigureOperationID         string    `gorm:"size:64;index" json:"configure_operation_id"`
	EnableOperationID            string    `gorm:"size:64;index" json:"enable_operation_id"`
	DisableOperationID           string    `gorm:"size:64;index" json:"disable_operation_id"`
	RollbackConfigureOperationID string    `gorm:"size:64;index" json:"rollback_configure_operation_id"`
	RollbackEnableOperationID    string    `gorm:"size:64;index" json:"rollback_enable_operation_id"`
	RollbackDisableOperationID   string    `gorm:"size:64;index" json:"rollback_disable_operation_id"`
	LastError                    string    `gorm:"type:text" json:"last_error"`
	CreatedAt                    time.Time `json:"created_at"`
	UpdatedAt                    time.Time `json:"updated_at"`
}

TopologyDeploymentStep is the durable, per-vertex execution plan for one immutable topology revision. It stores operation identities rather than an in-memory work queue so a Control restart can resume or compensate a partially applied deployment deterministically.

ApplyAction is either configure_enable or disable. RollbackMode is restore (configure the previous active revision and enable it) or disable (there was no previous vertex to restore). States are advanced only by the topology deployment executor.

func (TopologyDeploymentStep) TableName

func (TopologyDeploymentStep) TableName() string

type TopologyEdge

type TopologyEdge struct {
	ID         uint   `gorm:"primaryKey" json:"id"`
	RevisionID uint   `gorm:"not null;index" json:"revision_id"`
	SourceKey  string `gorm:"size:120;not null" json:"source_key"`
	TargetKey  string `gorm:"size:120;not null" json:"target_key"`
	Protocol   string `gorm:"size:48;not null" json:"protocol"`
	SecretID   string `gorm:"size:160" json:"secret_id"`
	ConfigJSON string `gorm:"type:text;not null" json:"config"`
}

func (TopologyEdge) TableName

func (TopologyEdge) TableName() string

type TopologyObservedState

type TopologyObservedState struct {
	ID               uint      `gorm:"primaryKey" json:"id"`
	DeploymentID     uint      `gorm:"not null;index;uniqueIndex:ux_observed_deployment_node" json:"deployment_id"`
	NodeID           uint      `gorm:"not null;uniqueIndex:ux_observed_deployment_node" json:"node_id"`
	DesiredRevision  int64     `gorm:"not null" json:"desired_revision"`
	ObservedRevision int64     `gorm:"not null" json:"observed_revision"`
	State            string    `gorm:"size:32;not null" json:"state"`
	HealthJSON       string    `gorm:"type:text" json:"health"`
	LastError        string    `gorm:"type:text" json:"last_error"`
	UpdatedAt        time.Time `json:"updated_at"`
}

func (TopologyObservedState) TableName

func (TopologyObservedState) TableName() string

type TopologyRevision

type TopologyRevision struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	TopologyID  uint      `gorm:"not null;uniqueIndex:ux_topology_revision" json:"topology_id"`
	Revision    int64     `gorm:"not null;uniqueIndex:ux_topology_revision" json:"revision"`
	State       string    `gorm:"size:24;not null;index" json:"state"`
	ContentHash string    `gorm:"size:64;not null" json:"content_hash"`
	Message     string    `gorm:"type:text" json:"message"`
	CreatedBy   uint      `gorm:"not null" json:"created_by"`
	CreatedAt   time.Time `json:"created_at"`
}

func (TopologyRevision) TableName

func (TopologyRevision) TableName() string

type TopologyVertex

type TopologyVertex struct {
	ID         uint   `gorm:"primaryKey" json:"id"`
	RevisionID uint   `gorm:"not null;index;uniqueIndex:ux_topology_vertex_key" json:"revision_id"`
	Key        string `gorm:"size:120;not null;uniqueIndex:ux_topology_vertex_key" json:"key"`
	Kind       string `gorm:"size:48;not null" json:"kind"`
	NodeID     *uint  `gorm:"index" json:"node_id"`
	PluginID   string `gorm:"size:120;index" json:"plugin_id"`
	Role       string `gorm:"size:80" json:"role"`
	ConfigJSON string `gorm:"type:text;not null" json:"config"`
}

func (TopologyVertex) TableName

func (TopologyVertex) TableName() string

type TrafficLog

type TrafficLog struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	UserID     uint      `gorm:"index;index:idx_server_log_log_at_user_id,priority:2" json:"user_id"`
	ServerID   uint      `gorm:"index" json:"server_id"`
	ServerType string    `gorm:"size:20" json:"server_type"`
	U          int64     `json:"u"` // upload bytes
	D          int64     `json:"d"` // download bytes
	Rate       float64   `gorm:"default:1" json:"rate"`
	LogAt      int64     `gorm:"index;index:idx_server_log_log_at_user_id,priority:1" json:"log_at"`
	CreatedAt  time.Time `json:"created_at"`
}

TrafficLog 流量日志

func (TrafficLog) TableName

func (TrafficLog) TableName() string

type USDTConfig

type USDTConfig struct {
	Network       string `json:"network"`        // 网络 (TRC20/ERC20/BEP20)
	WalletAddress string `json:"wallet_address"` // 收款钱包地址
	APIKey        string `json:"api_key"`        // 区块链API密钥 (可选)
	Confirmations int    `json:"confirmations"`  // 确认数
}

USDTConfig USDT支付配置

type User

type User struct {
	ID                uint      `gorm:"primaryKey" json:"id"`
	InviteUserID      *uint     `gorm:"index" json:"invite_user_id"`
	TelegramID        *int64    `json:"telegram_id"`
	Email             string    `gorm:"size:255;uniqueIndex" json:"email"`
	Password          string    `gorm:"size:255" json:"-"`
	PasswordAlgo      *string   `gorm:"size:20" json:"-"`
	PasswordSalt      *string   `gorm:"size:20" json:"-"`
	Balance           int64     `gorm:"default:0" json:"balance"`
	Discount          *int      `json:"discount"`
	CommissionType    int       `gorm:"default:0" json:"commission_type"`
	CommissionRate    *int      `json:"commission_rate"`
	CommissionBalance int64     `gorm:"default:0" json:"commission_balance"`
	Token             string    `gorm:"size:36;uniqueIndex" json:"token"`
	UUID              string    `gorm:"size:36;uniqueIndex" json:"uuid"`
	DeviceLimit       *int      `json:"device_limit"`
	SpeedLimit        *int64    `json:"speed_limit"`
	FlowResetTime     int64     `gorm:"default:0" json:"flowResetTime"`
	TransferEnable    int64     `gorm:"default:0" json:"transfer_enable"` // bytes
	U                 int64     `gorm:"default:0" json:"u"`               // upload bytes
	D                 int64     `gorm:"default:0" json:"d"`               // download bytes
	PlanID            *uint     `gorm:"index" json:"plan_id"`
	GroupID           *uint     `gorm:"index" json:"group_id"`
	ExpiredAt         *int64    `json:"expired_at"`
	Banned            int       `gorm:"default:0" json:"banned"`
	RemarkContent     *string   `gorm:"type:text" json:"remark_content"`
	IsAdmin           int       `gorm:"default:0" json:"is_admin"`
	IsStaff           int       `gorm:"default:0" json:"is_staff"`
	LastLoginAt       *int64    `json:"last_login_at"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`

	// Relations
	Plan *Plan `gorm:"foreignKey:PlanID" json:"plan,omitempty"`
}

User 用户模型

func (*User) GetDeviceLimit

func (u *User) GetDeviceLimit() int

GetDeviceLimit 获取设备限制

func (*User) GetSpeedLimit

func (u *User) GetSpeedLimit() int64

GetSpeedLimit 获取速度限制 (bytes/s)

func (*User) HasTraffic

func (u *User) HasTraffic() bool

HasTraffic 检查用户是否有剩余流量

func (*User) IsValid

func (u *User) IsValid() bool

IsValid 检查用户是否有效

func (User) TableName

func (User) TableName() string

type UserLevel

type UserLevel struct {
	ID    uint   `gorm:"primaryKey" json:"id"`
	Name  string `gorm:"size:50" json:"name"`
	Level int    `gorm:"uniqueIndex" json:"level"` // 等级数值
	Icon  string `gorm:"size:255" json:"icon"`     // 图标
	Color string `gorm:"size:20" json:"color"`     // 颜色

	// 权益
	Discount    int    `gorm:"default:0" json:"discount"` // 折扣百分比
	SpeedLimit  *int64 `json:"speed_limit"`               // 专属速度限制
	DeviceLimit *int   `json:"device_limit"`              // 专属设备限制

	// 升级条件
	MinDays    int     `gorm:"default:0" json:"min_days"`    // 最少使用天数
	MinTraffic int64   `gorm:"default:0" json:"min_traffic"` // 最少使用流量
	MinOrders  int     `gorm:"default:0" json:"min_orders"`  // 最少订单数
	MinAmount  float64 `gorm:"default:0" json:"min_amount"`  // 最少消费金额

	Enabled   bool      `gorm:"default:true" json:"enabled"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

UserLevel 用户等级

func (UserLevel) TableName

func (UserLevel) TableName() string

TableName 指定表名

type UserMFA

type UserMFA struct {
	ID      uint  `gorm:"primaryKey" json:"id"`
	UserID  uint  `gorm:"uniqueIndex" json:"user_id"`
	User    *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
	Enabled bool  `gorm:"default:false" json:"enabled"`

	// TOTP配置
	TOTPSecret  string `gorm:"size:100" json:"totp_secret"`   // TOTP密钥 (base32)
	BackupCodes string `gorm:"type:text" json:"backup_codes"` // 备用码 (JSON数组)

	// 短信/邮箱验证
	Phone         string `gorm:"size:20" json:"phone"` // 手机号
	PhoneVerified bool   `gorm:"default:false" json:"phone_verified"`

	// 最后使用时间
	LastUsed   *time.Time `json:"last_used"`
	LastMethod string     `gorm:"size:20" json:"last_method"` // totp/sms/email

	// 恢复信息
	RecoveryEmail string `gorm:"size:100" json:"recovery_email"` // 恢复邮箱

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

UserMFA 用户多因素认证

func (UserMFA) TableName

func (UserMFA) TableName() string

TableName 指定表名

type UserSubscriptionGroup

type UserSubscriptionGroup struct {
	ID             uint      `gorm:"primaryKey" json:"id"`
	UserID         uint      `gorm:"uniqueIndex:idx_user_group" json:"user_id"`
	GroupID        uint      `gorm:"uniqueIndex:idx_user_group" json:"group_id"`
	ExpireAt       *int64    `json:"expire_at"`        // 分组权限过期时间 (null=永不过期)
	TransferEnable *int64    `json:"transfer_enable"`  // 自定义总流量 (bytes), null 表示不覆盖用户默认
	NextRenewPrice *int64    `json:"next_renew_price"` // 下次续费价格 (单位分)
	CreatedAt      time.Time `json:"created_at"`

	// 关联
	User  *User              `gorm:"foreignKey:UserID" json:"user,omitempty"`
	Group *SubscriptionGroup `gorm:"foreignKey:GroupID" json:"group,omitempty"`
}

UserSubscriptionGroup 用户-订阅分组关联 (多对多) 用户可以属于多个分组,拥有多个分组的权限

func (UserSubscriptionGroup) TableName

func (UserSubscriptionGroup) TableName() string

type WechatPayConfig

type WechatPayConfig struct {
	AppID     string `json:"app_id"`     // 应用ID
	MchID     string `json:"mch_id"`     // 商户号
	APIKey    string `json:"api_key"`    // API密钥
	APIV3Key  string `json:"api_v3_key"` // APIv3密钥
	CertPath  string `json:"cert_path"`  // 商户证书路径
	KeyPath   string `json:"key_path"`   // 商户私钥路径
	NotifyURL string `json:"notify_url"` // 异步通知地址
	Sandbox   bool   `json:"sandbox"`    // 沙箱模式
}

WechatPayConfig 微信支付配置

type WireGuardPeer

type WireGuardPeer struct {
	ID             uint      `gorm:"primaryKey" json:"id"`
	NodeProtocolID uint      `gorm:"uniqueIndex:idx_wg_peer_protocol_user;index;uniqueIndex:idx_wg_peer_protocol_ip" json:"node_protocol_id"`
	UserID         uint      `gorm:"uniqueIndex:idx_wg_peer_protocol_user;index" json:"user_id"`
	PeerIP         string    `gorm:"size:64;uniqueIndex:idx_wg_peer_protocol_ip" json:"peer_ip"`
	PrivateKey     string    `gorm:"size:64" json:"-"`
	PublicKey      string    `gorm:"size:64" json:"public_key"`
	PresharedKey   string    `gorm:"size:64" json:"-"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`

	NodeProtocol *NodeProtocol `gorm:"foreignKey:NodeProtocolID" json:"node_protocol,omitempty"`
	User         *User         `gorm:"foreignKey:UserID" json:"user,omitempty"`
}

WireGuardPeer stores the panel-managed per-user WireGuard credentials for a concrete node protocol. It is keyed by protocol+user so subscriptions stay stable across refreshes.

func (WireGuardPeer) TableName

func (WireGuardPeer) TableName() string

type X402Config

type X402Config struct {
	WalletAddress string   `json:"wallet_address"` // 收款钱包地址
	Network       string   `json:"network"`        // 网络 (ethereum, polygon, arbitrum, base, sepolia等)
	AcceptTokens  []string `json:"accept_tokens"`  // 接受的代币 (ETH, USDT, USDC等)
	TestMode      bool     `json:"test_mode"`      // 是否测试模式 (使用测试链)
	WebhookSecret string   `json:"webhook_secret"` // Webhook 密钥
	ConfirmBlocks int      `json:"confirm_blocks"` // 确认区块数
}

X402Config X402 虚拟货币支付配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL