From 5c81baf7f1607d80c1195e306971be600222829c Mon Sep 17 00:00:00 2001 From: Nate Meyer <672246+notnmeyer@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:28:51 -0800 Subject: [PATCH 1/2] healthcheck --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index a1f70e8..deb6ed2 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,9 @@ func init() { } func main() { + // exempt from required headers, etc. + http.HandleFunc("/healthcheck", healthcheckHandler) + http.HandleFunc("/", handler) listenAddr := fmt.Sprintf(":%d", c.port) fmt.Printf("Listening on %s...\n", listenAddr) @@ -31,6 +34,11 @@ func main() { } } +func healthcheckHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) +} + func handler(w http.ResponseWriter, r *http.Request) { switch r.Method { case "OPTIONS": From 58fd9d06883d51cc14eb0aaa8703255286954b28 Mon Sep 17 00:00:00 2001 From: Nate Meyer <672246+notnmeyer@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:31:36 -0800 Subject: [PATCH 2/2] do it inline --- main.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index deb6ed2..585d11b 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,9 @@ func init() { func main() { // exempt from required headers, etc. - http.HandleFunc("/healthcheck", healthcheckHandler) + http.HandleFunc("/healthcheck", func(w http.ResponseWriter, t *http.Request) { + w.WriteHeader(http.StatusOK) + }) http.HandleFunc("/", handler) listenAddr := fmt.Sprintf(":%d", c.port) @@ -34,11 +36,6 @@ func main() { } } -func healthcheckHandler(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - w.Write([]byte("ok")) -} - func handler(w http.ResponseWriter, r *http.Request) { switch r.Method { case "OPTIONS":