From 1a33c0079dc4da8a17bfe57e38a0f9e5ccce4254 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 13 Feb 2026 21:44:22 +0800 Subject: [PATCH] fix(api): update health endpoint to return detailed health info - Changed the response type of the health endpoint to use a new HealthMap type for better clarity. - Updated the health information retrieval method to GetHealthInfoWithoutDetail for improved accuracy in the response. - Adjusted Swagger documentation to reflect the new response structure. --- internal/api/v1/docs/swagger.json | 84 +++++++++++++++++-------------- internal/api/v1/docs/swagger.yaml | 42 ++++++++-------- internal/api/v1/health.go | 9 ++-- internal/types/health.go | 2 - 4 files changed, 74 insertions(+), 63 deletions(-) diff --git a/internal/api/v1/docs/swagger.json b/internal/api/v1/docs/swagger.json index 0dcffb22..6964777a 100644 --- a/internal/api/v1/docs/swagger.json +++ b/internal/api/v1/docs/swagger.json @@ -855,7 +855,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/github_com_yusing_goutils_events.Event" + "$ref": "#/definitions/Event" } } }, @@ -1210,10 +1210,7 @@ "200": { "description": "Health info by route name", "schema": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/HealthStatusString" - } + "$ref": "#/definitions/HealthMap" } }, "403": { @@ -3827,6 +3824,42 @@ "x-nullable": false, "x-omitempty": false }, + "Event": { + "type": "object", + "properties": { + "action": { + "type": "string", + "x-nullable": false, + "x-omitempty": false + }, + "category": { + "type": "string", + "x-nullable": false, + "x-omitempty": false + }, + "data": { + "x-nullable": false, + "x-omitempty": false + }, + "level": { + "$ref": "#/definitions/events.Level", + "x-nullable": false, + "x-omitempty": false + }, + "timestamp": { + "type": "string", + "x-nullable": false, + "x-omitempty": false + }, + "uuid": { + "type": "string", + "x-nullable": false, + "x-omitempty": false + } + }, + "x-nullable": false, + "x-omitempty": false + }, "FileType": { "type": "string", "enum": [ @@ -3996,7 +4029,6 @@ "type": "object", "properties": { "latency": { - "description": "latency in microseconds", "type": "number", "x-nullable": false, "x-omitempty": false @@ -4015,7 +4047,6 @@ "x-omitempty": false }, "uptime": { - "description": "uptime in milliseconds", "type": "number", "x-nullable": false, "x-omitempty": false @@ -4088,6 +4119,14 @@ "x-nullable": false, "x-omitempty": false }, + "HealthMap": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/HealthInfoWithoutDetail" + }, + "x-nullable": false, + "x-omitempty": false + }, "HealthStatusString": { "type": "string", "enum": [ @@ -6718,37 +6757,6 @@ "x-nullable": false, "x-omitempty": false }, - "github_com_yusing_goutils_events.Event": { - "type": "object", - "properties": { - "action": { - "type": "string", - "x-nullable": false, - "x-omitempty": false - }, - "category": { - "type": "string", - "x-nullable": false, - "x-omitempty": false - }, - "data": { - "x-nullable": false, - "x-omitempty": false - }, - "level": { - "$ref": "#/definitions/events.Level", - "x-nullable": false, - "x-omitempty": false - }, - "timestamp": { - "type": "string", - "x-nullable": false, - "x-omitempty": false - } - }, - "x-nullable": false, - "x-omitempty": false - }, "icons.Source": { "type": "string", "enum": [ diff --git a/internal/api/v1/docs/swagger.yaml b/internal/api/v1/docs/swagger.yaml index 6959aabe..8e5b39ff 100644 --- a/internal/api/v1/docs/swagger.yaml +++ b/internal/api/v1/docs/swagger.yaml @@ -295,6 +295,20 @@ definitions: message: type: string type: object + Event: + properties: + action: + type: string + category: + type: string + data: {} + level: + $ref: '#/definitions/events.Level' + timestamp: + type: string + uuid: + type: string + type: object FileType: enum: - config @@ -375,7 +389,6 @@ definitions: HealthInfoWithoutDetail: properties: latency: - description: latency in microseconds type: number status: enum: @@ -387,7 +400,6 @@ definitions: - unknown type: string uptime: - description: uptime in milliseconds type: number type: object HealthJSON: @@ -419,6 +431,10 @@ definitions: url: type: string type: object + HealthMap: + additionalProperties: + $ref: '#/definitions/HealthInfoWithoutDetail' + type: object HealthStatusString: enum: - unknown @@ -1755,18 +1771,6 @@ definitions: - LevelInfo - LevelWarn - LevelError - github_com_yusing_goutils_events.Event: - properties: - action: - type: string - category: - type: string - data: {} - level: - $ref: '#/definitions/events.Level' - timestamp: - type: string - type: object icons.Source: enum: - https:// @@ -1828,12 +1832,12 @@ definitions: type: string kernel_version: type: string + load_avg_15m: + type: string load_avg_1m: type: string load_avg_5m: type: string - load_avg_15m: - type: string mem_pct: type: string mem_total: @@ -2484,7 +2488,7 @@ paths: description: OK schema: items: - $ref: '#/definitions/github_com_yusing_goutils_events.Event' + $ref: '#/definitions/Event' type: array "403": description: 'Forbidden: unauthorized' @@ -2721,9 +2725,7 @@ paths: "200": description: Health info by route name schema: - additionalProperties: - $ref: '#/definitions/HealthStatusString' - type: object + $ref: '#/definitions/HealthMap' "403": description: Forbidden schema: diff --git a/internal/api/v1/health.go b/internal/api/v1/health.go index f1e9badb..62c48b01 100644 --- a/internal/api/v1/health.go +++ b/internal/api/v1/health.go @@ -6,11 +6,14 @@ import ( "github.com/gin-gonic/gin" entrypoint "github.com/yusing/godoxy/internal/entrypoint/types" + "github.com/yusing/godoxy/internal/types" "github.com/yusing/goutils/apitypes" "github.com/yusing/goutils/http/httpheaders" "github.com/yusing/goutils/http/websocket" ) +type HealthMap = map[string]types.HealthInfoWithoutDetail // @name HealthMap + // @x-id "health" // @BasePath /api/v1 // @Summary Get routes health info @@ -18,7 +21,7 @@ import ( // @Tags v1,websocket // @Accept json // @Produce json -// @Success 200 {object} map[string]types.HealthStatusString "Health info by route name" +// @Success 200 {object} HealthMap "Health info by route name" // @Failure 403 {object} apitypes.ErrorResponse // @Failure 500 {object} apitypes.ErrorResponse // @Router /health [get] @@ -30,9 +33,9 @@ func Health(c *gin.Context) { } if httpheaders.IsWebsocket(c.Request.Header) { websocket.PeriodicWrite(c, 1*time.Second, func() (any, error) { - return ep.GetHealthInfoSimple(), nil + return ep.GetHealthInfoWithoutDetail(), nil }) } else { - c.JSON(http.StatusOK, ep.GetHealthInfoSimple()) + c.JSON(http.StatusOK, ep.GetHealthInfoWithoutDetail()) } } diff --git a/internal/types/health.go b/internal/types/health.go index 47c9a0ed..4134eaa2 100644 --- a/internal/types/health.go +++ b/internal/types/health.go @@ -85,8 +85,6 @@ type ( HealthInfoWithoutDetail Detail string `json:"detail"` } // @name HealthInfo - - HealthMap = map[string]HealthStatusString // @name HealthMap ) const (