Skip to content

Commit 19e0c13

Browse files
committed
Update.
1 parent 6a0259f commit 19e0c13

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

service/singleton/api.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func (s *ServerAPIService) GetStatusByIDList(idList []uint64) *ServerStatusRespo
135135

136136
// 如果没有有效的Host或状态数据,跳过该服务器
137137
if host == nil {
138-
continue
138+
// 确保至少有一个空的Host对象,避免前端报错
139+
host = &model.Host{}
139140
}
140141

141142
ipv4, ipv6, validIP := utils.SplitIPAddr(host.IP)
@@ -193,9 +194,9 @@ func (s *ServerAPIService) GetAllStatus() *ServerStatusResponse {
193194
}
194195
}
195196

196-
// 如果Host信息不可用,跳过此服务器
197+
// 如果Host信息不可用,创建一个空对象而不是跳过
197198
if host == nil {
198-
continue
199+
host = &model.Host{}
199200
}
200201

201202
// 获取状态数据,优先使用当前状态,没有则使用离线前保存的最后状态
@@ -244,7 +245,8 @@ func (s *ServerAPIService) GetListByTag(tag string) *ServerInfoResponse {
244245
for _, v := range ServerTagToIDList[tag] {
245246
host := ServerList[v].Host
246247
if host == nil {
247-
continue
248+
// 使用空对象而不是跳过
249+
host = &model.Host{}
248250
}
249251
ipv4, ipv6, validIP := utils.SplitIPAddr(host.IP)
250252
info := &CommonServerInfo{
@@ -275,7 +277,8 @@ func (s *ServerAPIService) GetAllList() *ServerInfoResponse {
275277
for _, v := range ServerList {
276278
host := v.Host
277279
if host == nil {
278-
continue
280+
// 使用空对象而不是跳过
281+
host = &model.Host{}
279282
}
280283
ipv4, ipv6, validIP := utils.SplitIPAddr(host.IP)
281284
info := &CommonServerInfo{

service/singleton/server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ func loadServers() {
4545
if err := DB.Raw("SELECT host_json FROM last_reported_host WHERE server_id = ?", innerS.ID).Scan(&hostJSON).Error; err == nil && len(hostJSON) > 0 {
4646
if err := utils.Json.Unmarshal(hostJSON, innerS.Host); err != nil {
4747
log.Printf("NG>> 解析服务器 %s 的Host数据失败: %v", innerS.Name, err)
48+
} else if Conf.Debug {
49+
log.Printf("NG>> 服务器 %s 成功加载Host数据: CPU=%v, MemTotal=%v",
50+
innerS.Name, len(innerS.Host.CPU) > 0, innerS.Host.MemTotal > 0)
51+
}
52+
} else if Conf.Debug {
53+
if err != nil {
54+
log.Printf("NG>> 服务器 %s 从数据库加载Host数据失败: %v", innerS.Name, err)
55+
} else {
56+
log.Printf("NG>> 服务器 %s 的Host数据在数据库中不存在或为空", innerS.Name)
4857
}
4958
}
5059

0 commit comments

Comments
 (0)