mirror of https://github.com/poanetwork/gecko.git
commit
c6bdd5247f
|
@ -38,7 +38,18 @@ func (h *Health) Handler() *common.HTTPHandler {
|
||||||
newServer.RegisterCodec(codec, "application/json")
|
newServer.RegisterCodec(codec, "application/json")
|
||||||
newServer.RegisterCodec(codec, "application/json;charset=UTF-8")
|
newServer.RegisterCodec(codec, "application/json;charset=UTF-8")
|
||||||
newServer.RegisterService(h, "health")
|
newServer.RegisterService(h, "health")
|
||||||
return &common.HTTPHandler{LockOptions: common.NoLock, Handler: newServer}
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == http.MethodGet { // GET request --> return 200 if getLiveness returns true, else 500
|
||||||
|
if _, healthy := h.health.Results(); healthy {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newServer.ServeHTTP(w, r) // Other request --> use JSON RPC
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return &common.HTTPHandler{LockOptions: common.NoLock, Handler: handler}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterHeartbeat adds a check with default options and a CheckFn that checks
|
// RegisterHeartbeat adds a check with default options and a CheckFn that checks
|
||||||
|
|
Loading…
Reference in New Issue