frostfs-http-gw/health.go

35 lines
756 B
Go
Raw Normal View History

2020-03-03 10:34:26 +00:00
package main
import (
"github.com/fasthttp/router"
"github.com/valyala/fasthttp"
"go.uber.org/atomic"
)
const (
healthyState = "NeoFS HTTP Gateway is "
defaultContentType = "text/plain; charset=utf-8"
)
func attachHealthy(r *router.Router, e *atomic.Error) {
2020-03-31 08:37:10 +00:00
r.GET("/-/ready/", func(ctx *fasthttp.RequestCtx) {
2020-03-03 10:34:26 +00:00
ctx.SetStatusCode(fasthttp.StatusOK)
ctx.SetBodyString(healthyState + "ready")
})
2020-03-31 08:37:10 +00:00
r.GET("/-/healthy/", func(c *fasthttp.RequestCtx) {
2020-03-03 10:34:26 +00:00
code := fasthttp.StatusOK
msg := "healthy"
if err := e.Load(); err != nil {
msg = "unhealthy: " + err.Error()
code = fasthttp.StatusBadRequest
}
c.Response.Reset()
c.SetStatusCode(code)
c.SetContentType(defaultContentType)
c.SetBodyString(healthyState + msg)
})
}