Files
platform/web/models/edge.go
2026-06-12 16:51:08 +08:00

69 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"platform/web/core"
"platform/web/globals/orm"
)
// Edge 节点表
type Edge struct {
core.Model
Type EdgeType `json:"type" gorm:"column:type"` // 节点类型1-自建2-GOST chain
Version int32 `json:"version" gorm:"column:version"` // 节点版本
Mac string `json:"mac" gorm:"column:mac"` // 节点 mac 地址或 GOST chain 名称
IP orm.Inet `json:"ip" gorm:"column:ip;not null"` // 节点地址或 GOST chain addr 的 IP
Port *uint16 `json:"port,omitempty" gorm:"column:port"` // GOST chain addr 的端口
ISP EdgeISP `json:"isp" gorm:"column:isp"` // 运营商0-未知1-电信2-联通3-移动
AreaID *int32 `json:"area_id,omitempty" gorm:"column:area_id"` // 城市地区ID
Status EdgeStatus `json:"status" gorm:"column:status"` // 节点状态0-离线1-正常
RTT int32 `json:"rtt" gorm:"column:rtt"` // 最近平均延迟
Loss int32 `json:"loss" gorm:"column:loss"` // 最近丢包率
Area *Area `json:"area,omitempty" gorm:"foreignKey:AreaID"` // 地区
}
// EdgeType 节点类型枚举
type EdgeType int
const (
EdgeTypeSelfBuilt EdgeType = 1 // 自建
EdgeTypeGostChain EdgeType = 2 // GOST chain
)
// EdgeStatus 节点状态枚举
type EdgeStatus int
const (
EdgeStatusOffline EdgeStatus = 0 // 离线
EdgeStatusNormal EdgeStatus = 1 // 正常
)
// EdgeISP 运营商枚举
type EdgeISP int
const (
EdgeISPUnknown EdgeISP = 0 // 未知/任意
EdgeISPTelecom EdgeISP = 1 // 电信
EdgeISPUnicom EdgeISP = 2 // 联通
EdgeISPMobile EdgeISP = 3 // 移动
)
func (isp *EdgeISP) String() string {
if isp == nil {
return ""
}
switch *isp {
case EdgeISPTelecom:
return "电信"
case EdgeISPUnicom:
return "联通"
case EdgeISPMobile:
return "移动"
default:
return ""
}
}
func ToEdgeISP(i int) EdgeISP {
return EdgeISP(i)
}