diff --git a/server/controllers/health.go b/server/controllers/health.go index 97ab8cf..6842773 100644 --- a/server/controllers/health.go +++ b/server/controllers/health.go @@ -18,6 +18,7 @@ import ( "fmt" "net/http" + "github.com/auula/urnadb/server/response" "github.com/auula/urnadb/utils" "github.com/gin-gonic/gin" ) @@ -35,7 +36,7 @@ type SystemInfo struct { } func GetHealthController(ctx *gin.Context) { - ctx.IndentedJSON(http.StatusOK, SystemInfo{ + ctx.IndentedJSON(http.StatusOK, response.Ok("server is healthy", SystemInfo{ GCState: hs.RegionCompactStatus(), KeyCount: hs.RegionInodeCount(), DiskFree: fmt.Sprintf("%.2fGB", utils.BytesToGB(hs.GetFreeDisk())), @@ -45,5 +46,5 @@ func GetHealthController(ctx *gin.Context) { MemoryTotal: fmt.Sprintf("%.2fGB", utils.BytesToGB(hs.GetTotalMemory())), SpaceTotalUsed: fmt.Sprintf("%.2fGB", utils.BytesToGB(hs.GetTotalSpaceUsed())), DiskPercent: fmt.Sprintf("%.2f%%", hs.GetDiskPercent()), - }) + })) } diff --git a/server/controllers/query.go b/server/controllers/query.go index 3cf2a8b..8f60d9d 100644 --- a/server/controllers/query.go +++ b/server/controllers/query.go @@ -38,7 +38,7 @@ func QueryController(ctx *gin.Context) { defer utils.ReleaseToPool(seg) ttl, _ := seg.ExpiresIn() - ctx.IndentedJSON(http.StatusOK, response.Ok("Key metadata query completed successfully", gin.H{ + ctx.IndentedJSON(http.StatusOK, response.Ok("metadata query completed successfully", gin.H{ "type": seg.GetTypeString(), "key": seg.GetKeyString(), "value": seg.Value, diff --git a/server/controllers/records.go b/server/controllers/records.go index 9a77914..869d69c 100644 --- a/server/controllers/records.go +++ b/server/controllers/records.go @@ -41,9 +41,7 @@ func GetRecordsController(ctx *gin.Context) { defer rd.ReleaseToPool() - ctx.IndentedJSON(http.StatusOK, response.Ok("record queried successfully", gin.H{ - "record": rd.Record, - })) + ctx.IndentedJSON(http.StatusOK, response.Ok("record queried successfully", rd.Record)) } type CreateRecordRequest struct { @@ -119,9 +117,7 @@ func SearchRecordsController(ctx *gin.Context) { return } - ctx.IndentedJSON(http.StatusOK, response.Ok("search completed successfully", gin.H{ - "column": res, - })) + ctx.IndentedJSON(http.StatusOK, response.Ok("search completed successfully", res)) } func handlerRecordsError(ctx *gin.Context, err error) { diff --git a/server/controllers/tables.go b/server/controllers/tables.go index 16f6fae..cd9c2f9 100644 --- a/server/controllers/tables.go +++ b/server/controllers/tables.go @@ -87,9 +87,7 @@ func QueryTableController(ctx *gin.Context) { return } - ctx.IndentedJSON(http.StatusOK, response.Ok("table queried successfully", gin.H{ - "table": tab.Table, - })) + ctx.IndentedJSON(http.StatusOK, response.Ok("table queried successfully", tab.Table)) } type PatchRowsRequest struct { @@ -144,9 +142,7 @@ func QueryRowsTableController(ctx *gin.Context) { return } - ctx.IndentedJSON(http.StatusOK, response.Ok("table queried rows successfully", gin.H{ - "rows": rows, - })) + ctx.IndentedJSON(http.StatusOK, response.Ok("table queried rows successfully", rows)) } func RemoveRowsTabelController(ctx *gin.Context) { diff --git a/server/controllers/variants.go b/server/controllers/variants.go index 8965c6a..32bc2ab 100644 --- a/server/controllers/variants.go +++ b/server/controllers/variants.go @@ -99,7 +99,7 @@ func CreateVariantController(ctx *gin.Context) { } // 成功响应 - ctx.IndentedJSON(http.StatusOK, response.Ok("", gin.H{ + ctx.IndentedJSON(http.StatusOK, response.Ok("variant created successfully", gin.H{ "variant": new_variant.Value, })) } diff --git a/server/routes/api.go b/server/routes/api.go index ee8ebbc..066d7c3 100644 --- a/server/routes/api.go +++ b/server/routes/api.go @@ -40,7 +40,7 @@ func SetupRoutes() *gin.Engine { router.NoMethod(controllers.Error404Handler) // 健康检查 - router.GET("/", controllers.GetHealthController) + router.GET("/health", controllers.GetHealthController) // 查询路由 query := router.Group("/query")