Skip to content

Commit

Permalink
Add endpoint for changing health status
Browse files Browse the repository at this point in the history
  • Loading branch information
jskswamy committed Feb 7, 2019
1 parent dadcd0a commit 9c7d0fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ var statusCode = 200

// Health return the dobby health status
func Health(c *gin.Context) {
c.JSON(statusCode, gin.H{"healthy": true})
healthy := true
if statusCode != 200 {
healthy = false
}
c.JSON(statusCode, gin.H{"healthy": healthy})
}

// Version return dobby version
Expand All @@ -30,6 +34,18 @@ func Crash(_ *gin.Context) {
log.Fatal("you asked me do so, killing myself :-)")
}

// Sick will make dobby sick
func Sick(c *gin.Context) {
statusCode = 500
c.JSON(200, gin.H{"status": "success"})
}

// Healthy will make dobby healthy again
func Healthy(c *gin.Context) {
statusCode = 200
c.JSON(200, gin.H{"status": "success"})
}

func init() {
healthy, err := strconv.ParseBool(os.Getenv("HEALTH"))

Expand Down
2 changes: 2 additions & 0 deletions pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ func Run(bindAddress, port string) error {
r.GET("/health", handler.Health)
r.GET("/version", handler.Version)
r.PUT("/state/crash", handler.Crash)
r.PUT("/state/sick", handler.Sick)
r.PUT("/state/healthy", handler.Healthy)
return r.Run(fmt.Sprintf("%s:%s", bindAddress, port))
}

0 comments on commit 9c7d0fb

Please sign in to comment.