Skip to content

Commit

Permalink
Update node/health.go
Browse files Browse the repository at this point in the history
Co-authored-by: Łukasz Magiera <magik6k@users.noreply.github.com>
  • Loading branch information
Cory Schwartz and magik6k authored May 23, 2022
1 parent 444d0b1 commit b485203
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions node/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b485203

Please sign in to comment.