safesight/control/internal/models/device.go
tian 98e375dc36 chore: 合并 safesight-control 仓库为 control/ 子目录
项目合并为单仓库:设备端(根) + 管理端(control/)。
两端 git 历史完整保留(git subtree 合并)。

git-subtree-dir: control
git-subtree-mainline: 923ab10d5c
git-subtree-split: 70738edb31
2026-08-02 11:13:26 +08:00

66 lines
1.8 KiB
Go

package models
import "sync"
type Device struct {
DeviceID string `json:"device_id"`
Hostname string `json:"hostname,omitempty"`
IP string `json:"ip"`
AgentPort int `json:"agent_port"`
MediaPort int `json:"media_port"`
DeviceAlias string `json:"device_alias,omitempty"`
DeviceName string `json:"device_name"`
InstanceName string `json:"instance_name,omitempty"`
InstanceDisplayName string `json:"instance_display_name,omitempty"`
Version string `json:"version"`
BuildID string `json:"build_id,omitempty"`
GitSha string `json:"git_sha"`
UptimeSec int64 `json:"uptime_sec,omitempty"`
LastSeenMs int64 `json:"last_seen_ms"`
Online bool `json:"online"`
Graphs interface{} `json:"graphs,omitempty"` // 摘要或详情
}
type DeviceRegistry struct {
Mu sync.RWMutex
Devices map[string]*Device
}
func NewDeviceRegistry() *DeviceRegistry {
return &DeviceRegistry{
Devices: make(map[string]*Device),
}
}
func (d *Device) DisplayName() string {
if d == nil {
return ""
}
if d.DeviceAlias != "" {
return d.DeviceAlias
}
if d.DeviceName != "" {
return d.DeviceName
}
if d.Hostname != "" {
return d.Hostname
}
if d.DeviceID != "" {
return d.DeviceID
}
return "-"
}
func (d *Device) TechnicalName() string {
if d == nil {
return ""
}
if d.Hostname != "" && d.Hostname != d.DeviceAlias {
return d.Hostname
}
if d.DeviceName != "" && d.DeviceName != d.DeviceAlias {
return d.DeviceName
}
return ""
}