更新 api 成功和失败响应

This commit is contained in:
dushixiang committed 2026-01-09 20:05:31 +08:00
1 parent 7092a67fe1
commit 7ea1122b31
8 files changed
+36 -70

No files matched your search

+1 -3
View File
@@ -129,9 +129,7 @@ func (r AccountHandler) Logout(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "登出成功",
})
return orz.Ok(c, orz.Map{})
}
// ValidateToken 验证 token(供中间件使用)
+4 -12
View File
@@ -159,9 +159,7 @@ func (h *AgentHandler) UpdateInfo(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "更新成功",
})
return orz.Ok(c, orz.Map{})
}
// GetStatistics 获取探针统计数据
@@ -225,9 +223,7 @@ func (h *AgentHandler) Delete(c echo.Context) error {
zap.String("agentID", agentID),
zap.String("name", agent.Name))
return orz.Ok(c, orz.Map{
"message": "删除成功",
})
return orz.Ok(c, orz.Map{})
}
// BatchUpdateTags 批量更新探针标签
@@ -285,9 +281,7 @@ func (h *AgentHandler) UpdateTrafficConfig(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "流量配置更新成功",
})
return orz.Ok(c, orz.Map{})
}
// GetTrafficStats 查询流量统计(管理员接口)
@@ -312,7 +306,5 @@ func (h *AgentHandler) ResetAgentTraffic(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "流量已重置",
})
return orz.Ok(c, orz.Map{})
}
+2 -4
View File
@@ -49,11 +49,9 @@ func (h *AlertHandler) ClearAlertRecords(c echo.Context) error {
if err := h.alertService.Clear(c.Request().Context()); err != nil {
h.logger.Error("清空告警记录失败", zap.Error(err))
return c.JSON(http.StatusInternalServerError, map[string]string{
"error": "清空告警记录失败",
"message": "清空告警记录失败",
})
}
return c.JSON(http.StatusOK, map[string]string{
"message": "清空成功",
})
return c.JSON(http.StatusOK, echo.Map{})
}
+5 -16
View File
@@ -46,10 +46,7 @@ func (r ApiKeyHandler) Paging(c echo.Context) error {
}
// 返回完整密钥,由前端控制显示/隐藏
return orz.Ok(c, orz.Map{
"items": page.Items,
"total": page.Total,
})
return orz.Ok(c, page)
}
// Create 生成API密钥
@@ -108,9 +105,7 @@ func (r ApiKeyHandler) Update(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "API密钥名称更新成功",
})
return orz.Ok(c, orz.Map{})
}
// Delete 删除API密钥
@@ -123,9 +118,7 @@ func (r ApiKeyHandler) Delete(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "API密钥删除成功",
})
return orz.Ok(c, orz.Map{})
}
// Enable 启用API密钥
@@ -138,9 +131,7 @@ func (r ApiKeyHandler) Enable(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "API密钥启用成功",
})
return orz.Ok(c, orz.Map{})
}
// Disable 禁用API密钥
@@ -153,7 +144,5 @@ func (r ApiKeyHandler) Disable(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "API密钥禁用成功",
})
return orz.Ok(c, orz.Map{})
}
+5 -15
View File
@@ -196,9 +196,7 @@ func (h *DDNSHandler) Update(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "DDNS 配置更新成功",
})
return orz.Ok(c, orz.Map{})
}
// Delete 删除 DDNS 配置
@@ -211,9 +209,7 @@ func (h *DDNSHandler) Delete(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "DDNS 配置删除成功",
})
return orz.Ok(c, orz.Map{})
}
// Enable 启用 DDNS 配置
@@ -226,9 +222,7 @@ func (h *DDNSHandler) Enable(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "DDNS 配置启用成功",
})
return orz.Ok(c, orz.Map{})
}
// Disable 禁用 DDNS 配置
@@ -241,9 +235,7 @@ func (h *DDNSHandler) Disable(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "DDNS 配置禁用成功",
})
return orz.Ok(c, orz.Map{})
}
// GetRecords 获取 DDNS 更新记录
@@ -274,7 +266,5 @@ func (h *DDNSHandler) TriggerUpdate(c echo.Context) error {
return err
}
return orz.Ok(c, orz.Map{
"message": "DDNS 更新触发成功,探针将在几秒内上报 IP 并更新记录",
})
return orz.Ok(c, orz.Map{})
}
+3 -2
View File
@@ -6,6 +6,7 @@ import (
"github.com/dushixiang/pika/internal/models"
"github.com/dushixiang/pika/internal/service"
"github.com/go-orz/orz"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
@@ -126,7 +127,7 @@ func (h *DNSProviderHandler) Upsert(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "保存配置失败")
}
return c.JSON(http.StatusOK, map[string]string{"message": "保存成功"})
return c.JSON(http.StatusOK, orz.Map{})
}
// Delete 删除 DNS Provider 配置
@@ -143,7 +144,7 @@ func (h *DNSProviderHandler) Delete(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "删除配置失败")
}
return c.JSON(http.StatusOK, map[string]string{"message": "删除成功"})
return c.JSON(http.StatusOK, orz.Map{})
}
// validateProviderConfig 验证不同服务商的配置字段
+2 -3
View File
@@ -7,6 +7,7 @@ import (
"github.com/dushixiang/pika/internal/models"
"github.com/dushixiang/pika/internal/service"
"github.com/go-orz/orz"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
@@ -77,9 +78,7 @@ func (h *PropertyHandler) SetProperty(c echo.Context) error {
})
}
return c.JSON(http.StatusOK, map[string]string{
"message": "设置成功",
})
return c.JSON(http.StatusOK, orz.Map{})
}
// GetLogo 获取系统 Logo(公开访问,返回图片文件流)
+14 -15
View File
@@ -5,6 +5,7 @@ import (
"strconv"
"github.com/dushixiang/pika/internal/service"
"github.com/go-orz/orz"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
@@ -29,7 +30,7 @@ func (h *SSHLoginHandler) GetConfig(c echo.Context) error {
agentID := c.Param("id")
if agentID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "探针ID不能为空",
"message": "探针ID不能为空",
})
}
@@ -37,7 +38,7 @@ func (h *SSHLoginHandler) GetConfig(c echo.Context) error {
if err != nil {
h.logger.Error("获取SSH登录监控配置失败", zap.Error(err))
return c.JSON(http.StatusInternalServerError, map[string]string{
"error": "获取配置失败",
"message": "获取配置失败",
})
}
@@ -58,7 +59,7 @@ func (h *SSHLoginHandler) UpdateConfig(c echo.Context) error {
agentID := c.Param("id")
if agentID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "探针ID不能为空",
"message": "探针ID不能为空",
})
}
@@ -68,7 +69,7 @@ func (h *SSHLoginHandler) UpdateConfig(c echo.Context) error {
if err := c.Bind(&req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "请求参数错误",
"message": "请求参数错误",
})
}
@@ -76,7 +77,7 @@ func (h *SSHLoginHandler) UpdateConfig(c echo.Context) error {
if err != nil {
h.logger.Error("更新SSH登录监控配置失败", zap.Error(err))
return c.JSON(http.StatusInternalServerError, map[string]string{
"error": "更新配置失败",
"message": "更新配置失败",
})
}
@@ -101,7 +102,7 @@ func (h *SSHLoginHandler) ListEvents(c echo.Context) error {
agentID := c.Param("id")
if agentID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "探针ID不能为空",
"message": "探针ID不能为空",
})
}
@@ -138,7 +139,7 @@ func (h *SSHLoginHandler) ListEvents(c echo.Context) error {
if err != nil {
h.logger.Error("查询SSH登录事件失败", zap.Error(err))
return c.JSON(http.StatusInternalServerError, map[string]string{
"error": "查询失败",
"message": "查询失败",
})
}
@@ -156,7 +157,7 @@ func (h *SSHLoginHandler) GetEvent(c echo.Context) error {
eventID := c.Param("id")
if eventID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "事件ID不能为空",
"message": "事件ID不能为空",
})
}
@@ -164,13 +165,13 @@ func (h *SSHLoginHandler) GetEvent(c echo.Context) error {
if err != nil {
h.logger.Error("获取SSH登录事件失败", zap.Error(err))
return c.JSON(http.StatusInternalServerError, map[string]string{
"error": "获取事件失败",
"message": "获取事件失败",
})
}
if event == nil {
return c.JSON(http.StatusNotFound, map[string]string{
"error": "事件不存在",
"message": "事件不存在",
})
}
@@ -183,18 +184,16 @@ func (h *SSHLoginHandler) DeleteEvents(c echo.Context) error {
agentID := c.Param("id")
if agentID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "探针ID不能为空",
"message": "探针ID不能为空",
})
}
if err := h.service.DeleteEventsByAgentID(agentID); err != nil {
h.logger.Error("删除SSH登录事件失败", zap.Error(err))
return c.JSON(http.StatusInternalServerError, map[string]string{
"error": "删除失败",
"message": "删除失败",
})
}
return c.JSON(http.StatusOK, map[string]string{
"message": "删除成功",
})
return c.JSON(http.StatusOK, orz.Map{})
}