Skip to content

Commit

Permalink
add /clammit/readyz (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjt committed May 23, 2021
1 parent 0aad615 commit 635645a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func main() {

router.HandleFunc("/clammit", infoHandler)
router.HandleFunc("/clammit/scan", scanHandler)
router.HandleFunc("/clammit/readyz", readyzHandler)

if ctx.Config.App.TestPages {
fs := http.FileServer(http.Dir("testfiles"))
router.Handle("/clammit/test/", http.StripPrefix("/clammit/test/", fs))
Expand Down Expand Up @@ -386,3 +388,17 @@ func infoHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(s))
}

/*
* Handler for /clammit/readyz
*
* Returns 200 OK unless we are shutting down. Used in k8s.
* See https://github.com/ifad/clammit/issues/23
*/
func readyzHandler(w http.ResponseWriter, req *http.Request) {
if ctx.ShuttingDown {
w.WriteHeader(503)
} else {
w.WriteHeader(200)
}
}

0 comments on commit 635645a

Please sign in to comment.