frostfs-s3-gw/cmd/gate/app-healthy.go

38 lines
723 B
Go
Raw Normal View History

2020-07-06 09:18:16 +00:00
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
2020-07-12 23:00:47 +00:00
type Healthy interface {
Status() error
}
2020-07-06 09:18:16 +00:00
const (
healthyState = "NeoFS S3 Gateway is "
// defaultContentType = "text/plain; charset=utf-8"
)
2020-07-12 23:00:47 +00:00
func attachHealthy(r *mux.Router, h Healthy) {
2020-07-06 09:18:16 +00:00
r.HandleFunc("/-/ready", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprintln(w, healthyState+"ready")
})
r.HandleFunc("/-/healthy", func(w http.ResponseWriter, r *http.Request) {
code := http.StatusOK
msg := "healthy"
2020-07-12 23:00:47 +00:00
if err := h.Status(); err != nil {
2020-07-06 09:18:16 +00:00
msg = "unhealthy: " + err.Error()
code = http.StatusBadRequest
}
w.WriteHeader(code)
_, _ = fmt.Fprintln(w, healthyState+msg)
})
}