Skip to content

Commit dd3cb19

Browse files
committed
feat: add health endpoint
1 parent 2bfd290 commit dd3cb19

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ services:
33
build:
44
context: .
55
dockerfile: Dockerfile
6+
args:
7+
- VERSION=development
68
environment:
79
- PORT=8080
810
- ADDRESS=0.0.0.0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package controller
2+
3+
import "github.com/gin-gonic/gin"
4+
5+
type HealthController struct {
6+
router *gin.RouterGroup
7+
}
8+
9+
func NewHealthController(router *gin.RouterGroup) *HealthController {
10+
return &HealthController{
11+
router: router,
12+
}
13+
}
14+
15+
func (hc *HealthController) SetupRoutes() {
16+
hc.router.GET("/health", hc.health)
17+
hc.router.HEAD("/health", hc.health)
18+
}
19+
20+
func (hc *HealthController) health(c *gin.Context) {
21+
c.JSON(200, map[string]any{
22+
"status": 200,
23+
"message": "OK",
24+
})
25+
}

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func main() {
6868

6969
instancesCtrl.SetupRoutes()
7070

71+
healthCtrl := controller.NewHealthController(api)
72+
73+
healthCtrl.SetupRoutes()
74+
7175
go clearOldSessions(db)
7276

7377
log.Printf("Starting analytics server on %s:%s (version: %s)", address, port, version)

0 commit comments

Comments
 (0)