dockerhealth/health.go

36 lines
511 B
Go
Raw Permalink Normal View History

2021-12-13 02:28:09 +01:00
package dockerhealth
import (
2021-12-13 02:34:19 +01:00
"context"
2021-12-13 02:28:09 +01:00
"net/http"
)
var server = &http.Server{
Handler: new(httpHandler),
Addr: "localhost:60000",
}
var Healthy bool = true
func init() {
2021-12-13 02:34:19 +01:00
go func() {
server.ListenAndServe()
}()
}
func Stop() {
server.Shutdown(context.Background())
2021-12-13 02:28:09 +01:00
}
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)
}
}