-
-
Notifications
You must be signed in to change notification settings - Fork 600
/
health.go
46 lines (42 loc) · 956 Bytes
/
health.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
44
45
46
package api
import (
"github.com/gin-gonic/gin"
"github.com/gotify/server/v2/model"
)
// The HealthDatabase interface for encapsulating database access.
type HealthDatabase interface {
Ping() error
}
// The HealthAPI provides handlers for the health information.
type HealthAPI struct {
DB HealthDatabase
}
// Health returns health information.
// swagger:operation GET /health health getHealth
//
// Get health information.
//
// ---
// produces: [application/json]
// responses:
// 200:
// description: Ok
// schema:
// $ref: "#/definitions/Health"
// 500:
// description: Ok
// schema:
// $ref: "#/definitions/Health"
func (a *HealthAPI) Health(ctx *gin.Context) {
if err := a.DB.Ping(); err != nil {
ctx.JSON(500, model.Health{
Health: model.StatusOrange,
Database: model.StatusRed,
})
return
}
ctx.JSON(200, model.Health{
Health: model.StatusGreen,
Database: model.StatusGreen,
})
}