Skip to content

Commit 635645a

Browse files
committed
add /clammit/readyz (#23)
1 parent 0aad615 commit 635645a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ func main() {
186186

187187
router.HandleFunc("/clammit", infoHandler)
188188
router.HandleFunc("/clammit/scan", scanHandler)
189+
router.HandleFunc("/clammit/readyz", readyzHandler)
190+
189191
if ctx.Config.App.TestPages {
190192
fs := http.FileServer(http.Dir("testfiles"))
191193
router.Handle("/clammit/test/", http.StripPrefix("/clammit/test/", fs))
@@ -386,3 +388,17 @@ func infoHandler(w http.ResponseWriter, req *http.Request) {
386388
w.Header().Set("Content-Type", "application/json")
387389
w.Write([]byte(s))
388390
}
391+
392+
/*
393+
* Handler for /clammit/readyz
394+
*
395+
* Returns 200 OK unless we are shutting down. Used in k8s.
396+
* See https://github.com/ifad/clammit/issues/23
397+
*/
398+
func readyzHandler(w http.ResponseWriter, req *http.Request) {
399+
if ctx.ShuttingDown {
400+
w.WriteHeader(503)
401+
} else {
402+
w.WriteHeader(200)
403+
}
404+
}

0 commit comments

Comments
 (0)