1
package api
2

3
import (
4
    "net/http"
5

6
    "github.com/gin-gonic/gin"
7

8
    "github.com/earaujoassis/space/datastore"
9
)
10

11 0
func exposeHealthCheck(router *gin.RouterGroup) {
12 0
    healthCheckRoutes := router.Group("/")
13
    {
14 0
        healthCheckRoutes.GET("/health-check", func(c *gin.Context) {
15 0
            var count struct{
16 0
                Count int64
17
            }
18

19 0
            dataStoreSession := datastore.GetDataStoreConnection()
20 0
            dataStoreSession.
21 0
                Raw("SELECT count(*) AS count FROM clients;").
22 0
                Scan(&count)
23 0
            if count.Count >= 0 {
24 0
                c.String(http.StatusOK, "healthy")
25 0
            } else {
26 0
                c.String(http.StatusOK, "unhealthy")
27
            }
28
        })
29
    }
30
}

Read our documentation on viewing source code .

Loading