Update node/health.go

Co-authored-by: Łukasz Magiera <magik6k@users.noreply.github.com>
This commit is contained in:
Cory Schwartz 2022-05-23 11:11:45 -07:00 committed by GitHub
parent 444d0b1b8a
commit b4852038a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,15 +10,19 @@ import (
)
type HealthHandler struct {
healthy bool
healthy int32
}
func (h *HealthHandler) SetHealthy(healthy bool) {
h.healthy = healthy
h := int32(0)
if healthy {
h = 1
}
atomic.StoreInt32(&h.healthy, h)
}
func (h *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !h.healthy {
if atomic.LoadInt32(&h.healthy) != 1 {
w.WriteHeader(http.StatusServiceUnavailable)
return
}