This commit is contained in:
Julien Salleyron
2017-02-06 23:29:46 +01:00
parent 531a7e2b13
commit 5ebf416f43

4
app.go
View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"sync"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
// "github.com/pkg/profile" // "github.com/pkg/profile"
@ -135,6 +136,7 @@ type healthState struct {
} }
var currentHealthState = healthState{200} var currentHealthState = healthState{200}
var mutexHealthState = &sync.Mutex{}
func healthHandler(w http.ResponseWriter, req *http.Request) { func healthHandler(w http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodPost { if req.Method == http.MethodPost {
@ -145,7 +147,9 @@ func healthHandler(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(err.Error())) w.Write([]byte(err.Error()))
} else { } else {
fmt.Printf("Update health check status code [%d]\n", statusCode) fmt.Printf("Update health check status code [%d]\n", statusCode)
mutexHealthState.Lock()
currentHealthState.StatusCode = statusCode currentHealthState.StatusCode = statusCode
mutexHealthState.Unlock()
} }
} else { } else {
w.WriteHeader(currentHealthState.StatusCode) w.WriteHeader(currentHealthState.StatusCode)