chore: update echo response

This commit is contained in:
Steven
2023-03-16 08:08:52 +08:00
parent a6a8775153
commit 143bdb7596
5 changed files with 26 additions and 79 deletions

View File

@@ -1,7 +1,6 @@
package server
import (
"encoding/json"
"net/http"
"github.com/boojack/corgi/api"
@@ -11,13 +10,7 @@ import (
func (s *Server) registerSystemRoutes(g *echo.Group) {
g.GET("/ping", func(c echo.Context) error {
data := s.Profile
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(data)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose system profile").SetInternal(err)
}
return nil
return c.JSON(http.StatusOK, composeResponse(s.Profile))
})
g.GET("/status", func(c echo.Context) error {
@@ -25,10 +18,6 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
Profile: s.Profile,
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(systemStatus)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode system status response").SetInternal(err)
}
return nil
return c.JSON(http.StatusOK, composeResponse(systemStatus))
})
}