From b680ac34603eafae28ffe3287d07b1d4f2266aca Mon Sep 17 00:00:00 2001 From: Tordarus Date: Mon, 13 Dec 2021 02:28:09 +0100 Subject: [PATCH] initial commit --- go.mod | 3 +++ health.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 go.mod create mode 100644 health.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6f7d3ce --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.tordarus.net/Tordarus/dockerhealth + +go 1.17 diff --git a/health.go b/health.go new file mode 100644 index 0000000..725276b --- /dev/null +++ b/health.go @@ -0,0 +1,28 @@ +package dockerhealth + +import ( + "net/http" +) + +var server = &http.Server{ + Handler: new(httpHandler), + Addr: "localhost:60000", +} + +var Healthy bool = true + +func init() { + server.ListenAndServe() +} + +type httpHandler struct { + http.Handler +} + +func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if Healthy { + w.WriteHeader(http.StatusOK) + } else { + w.WriteHeader(http.StatusInternalServerError) + } +}