Skip to content

Commit 0448dac

Browse files
authored
Merge pull request #3 from cuappdev/josh-health
Edit healthcheck endpoint
2 parents 9617166 + 44b6324 commit 0448dac

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

controllers/healthcheck.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ package controllers
33
import (
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
1112
func 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
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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")

0 commit comments

Comments
 (0)