Skip to content

Commit 4d84e8c

Browse files
author
yangtao
committed
fix: dashbord empty data is null
1 parent 5a2283f commit 4d84e8c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

internal/api/dashboard.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,9 @@ func (h *DashboardHandler) HandleTrafficTrend(w http.ResponseWriter, r *http.Req
9090
return
9191
}
9292

93+
if trend == nil {
94+
trend = make([]dashboard.TrafficTrendItem, 0)
95+
}
96+
9397
json.NewEncoder(w).Encode(map[string]interface{}{"success": true, "data": trend, "count": len(trend)})
9498
}

internal/api/tunnel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ func (h *TunnelHandler) HandleGetTunnelLogs(w http.ResponseWriter, r *http.Reque
329329
return
330330
}
331331

332-
// 格式化为前端需要的字段
333-
var resp []map[string]interface{}
332+
// 格式化为前端需要的字段;若无数据也返回空数组而非 null
333+
resp := make([]map[string]interface{}, 0)
334334
for _, l := range logs {
335335
statusType := "warning"
336336
if l.Status == "success" {

0 commit comments

Comments
 (0)