forked from topfreegames/khan
/
healthcheck.go
43 lines (36 loc) · 1.06 KB
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// khan
// https://github.com/topfreegames/khan
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license
// Copyright © 2016 Top Free Games <backend@tfgco.com>
package api
import (
"fmt"
"net/http"
"strings"
"github.com/labstack/echo"
)
//HealthCheckHandler is the handler responsible for validating that the app is still up
func HealthCheckHandler(app *App) func(c echo.Context) error {
return func(c echo.Context) error {
c.Set("route", "Healthcheck")
db, err := app.GetCtxDB(c)
if err != nil {
return FailWith(http.StatusInternalServerError, err.Error(), c)
}
workingString := app.Config.GetString("healthcheck.workingText")
err = WithSegment("postgres", c, func() error {
_, err = db.SelectInt("select count(*) from games")
if err != nil {
return err
}
return nil
})
if err != nil {
return FailWith(http.StatusInternalServerError, fmt.Sprintf("Error connecting to database: %s", err), c)
}
workingString = strings.TrimSpace(workingString)
return c.String(http.StatusOK, workingString)
}
}