File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,11 @@ var statusCode = 200
1212
1313// Health return the dobby health status
1414func Health (c * gin.Context ) {
15- c .JSON (statusCode , gin.H {"healthy" : true })
15+ healthy := true
16+ if statusCode != 200 {
17+ healthy = false
18+ }
19+ c .JSON (statusCode , gin.H {"healthy" : healthy })
1620}
1721
1822// Version return dobby version
@@ -30,6 +34,18 @@ func Crash(_ *gin.Context) {
3034 log .Fatal ("you asked me do so, killing myself :-)" )
3135}
3236
37+ // Sick will make dobby sick
38+ func Sick (c * gin.Context ) {
39+ statusCode = 500
40+ c .JSON (200 , gin.H {"status" : "success" })
41+ }
42+
43+ // Healthy will make dobby healthy again
44+ func Healthy (c * gin.Context ) {
45+ statusCode = 200
46+ c .JSON (200 , gin.H {"status" : "success" })
47+ }
48+
3349func init () {
3450 healthy , err := strconv .ParseBool (os .Getenv ("HEALTH" ))
3551
Original file line number Diff line number Diff line change @@ -13,5 +13,7 @@ func Run(bindAddress, port string) error {
1313 r .GET ("/health" , handler .Health )
1414 r .GET ("/version" , handler .Version )
1515 r .PUT ("/state/crash" , handler .Crash )
16+ r .PUT ("/state/sick" , handler .Sick )
17+ r .PUT ("/state/healthy" , handler .Healthy )
1618 return r .Run (fmt .Sprintf ("%s:%s" , bindAddress , port ))
1719}
You can’t perform that action at this time.
0 commit comments