From 70fa4c4468b7b0810dd9074fb49490bd0ae00cab Mon Sep 17 00:00:00 2001 From: Simon Reinisch Date: Fri, 10 Nov 2023 17:51:26 +0100 Subject: [PATCH] feat: add health check endpoint --- Dockerfile | 2 ++ routes/health.go | 12 ++++++++++++ routes/setup.go | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 routes/health.go diff --git a/Dockerfile b/Dockerfile index 594231f..35d1117 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,4 +27,6 @@ ENV GENESIS_BUILD_VERSION=${GENESIS_BUILD_VERSION} ENV GENESIS_BUILD_DATE=${GENESIS_BUILD_DATE} ENV GENESIS_BUILD_COMMIT=${GENESIS_BUILD_COMMIT} +HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1 + CMD ["./genesis"] diff --git a/routes/health.go b/routes/health.go new file mode 100644 index 0000000..0e2c606 --- /dev/null +++ b/routes/health.go @@ -0,0 +1,12 @@ +package routes + +import ( + "github.com/gin-gonic/gin" + "net/http" +) + +func Health(c *gin.Context) { + + // We assume, if the api is able to respond to this request, it is healthy. + c.Status(http.StatusOK) +} diff --git a/routes/setup.go b/routes/setup.go index ed18c4b..24b8f46 100644 --- a/routes/setup.go +++ b/routes/setup.go @@ -34,5 +34,8 @@ func SetupRoutes() *gin.Engine { router.GET("/data/:key", DataByKey) router.GET("/data", Data) + // Heal check endpoints + router.GET("/health", Health) + return router }