Skip to content

Commit e86fb53

Browse files
committed
Respect 'HEALTH' env variable when returning the health status
1 parent a9e37e1 commit e86fb53

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/handler/handler.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import (
44
"github.com/gin-gonic/gin"
55
"github.com/thecasualcoder/dobby/pkg/config"
66
"os"
7+
"strconv"
78
)
89

10+
var statusCode = 200
11+
912
// Health return the dobby health status
1013
func Health(c *gin.Context) {
11-
c.JSON(200, gin.H{"healthy": true})
14+
c.JSON(statusCode, gin.H{"healthy": true})
1215
}
1316

1417
// Version return dobby version
@@ -20,3 +23,13 @@ func Version(c *gin.Context) {
2023
}
2124
c.JSON(200, gin.H{"version": version})
2225
}
26+
27+
func init() {
28+
healthy, err := strconv.ParseBool(os.Getenv("HEALTH"))
29+
30+
if err != nil {
31+
statusCode = 200
32+
} else if !healthy {
33+
statusCode = 500
34+
}
35+
}

0 commit comments

Comments
 (0)