File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,11 +3,21 @@ package controllers
33import (
44 "net/http"
55
6+ "github.com/cuappdev/chimes-backend/models"
67 "github.com/gin-gonic/gin"
78)
89
9- // GET /healthcheck
10+ // GET /health
1011// Get healthcheck
1112func HealthCheck (c * gin.Context ) {
12- c .JSON (http .StatusOK , gin.H {"status" : "Chimes is healthy!" })
13+ sqlDB , err := models .DB .DB ()
14+ if err != nil {
15+ c .JSON (http .StatusServiceUnavailable , gin.H {"status" : "unhealthy" , "database" : "disconnected" })
16+ return
17+ }
18+ if err := sqlDB .Ping (); err != nil {
19+ c .JSON (http .StatusServiceUnavailable , gin.H {"status" : "unhealthy" , "database" : "disconnected" })
20+ return
21+ }
22+ c .JSON (http .StatusOK , gin.H {"status" : "healthy" , "database" : "connected" })
1323}
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ func main() {
4949
5050 log .Println ("Setting up routes..." )
5151 // Public routes
52- r .GET ("/healthcheck " , controllers .HealthCheck )
52+ r .GET ("/health " , controllers .HealthCheck )
5353
5454 // Auth routes (public)
5555 api := r .Group ("/api" )
You can’t perform that action at this time.
0 commit comments