Skip to content

Commit

Permalink
feat: pre json marshal health body (#43)
Browse files Browse the repository at this point in the history
* feat: health improvement

* feat: pre json marshal
  • Loading branch information
garrettladley authored Sep 30, 2024
1 parent a4fd7d7 commit ebe3a05
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions backend/internal/handlers/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ import (

"github.com/GenerateNU/nightlife/internal/types"
"github.com/gofiber/fiber/v2"

go_json "github.com/goccy/go-json"
)

var health = &types.SysInfo{
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
CPUCores: runtime.NumCPU(),
GoVersion: runtime.Version(),
var healthBody []byte

func init() {
body := fiber.Map{
"status": "ok",
"system": &types.SysInfo{
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
CPUCores: runtime.NumCPU(),
GoVersion: runtime.Version(),
},
}

bodyBytes, err := go_json.Marshal(body)
if err != nil {
panic(err)
}

healthBody = bodyBytes
}

func (s *Service) GetHealth(c *fiber.Ctx) error {
return c.
Status(http.StatusOK).
JSON(
fiber.Map{
"status": "ok",
"system": health,
},
)
c.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSON)
return c.Status(http.StatusOK).Send(healthBody)
}

0 comments on commit ebe3a05

Please sign in to comment.