forked from TrueCloudLab/frostfs-http-gw
simplify main func
This commit is contained in:
parent
2db83caf29
commit
d0901587e2
1 changed files with 4 additions and 37 deletions
41
main.go
41
main.go
|
@ -7,8 +7,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
http "github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
|
@ -21,11 +19,6 @@ type app struct {
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
defaultHealthyMsg = "NeoFS HTTP Gateway is "
|
|
||||||
defaultContentType = "text/plain; charset=utf-8"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -52,45 +45,19 @@ func main() {
|
||||||
r.RedirectTrailingSlash = true
|
r.RedirectTrailingSlash = true
|
||||||
r.GET("/get/:cid/:oid", a.receiveFile)
|
r.GET("/get/:cid/:oid", a.receiveFile)
|
||||||
|
|
||||||
r.GET("/-/ready", func(ctx *fasthttp.RequestCtx) {
|
// attaching /-/(ready,healthy)
|
||||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
attachHealthy(r, a.pool.unhealthy)
|
||||||
ctx.SetBodyString("NeoFS HTTP Gateway is ready")
|
|
||||||
})
|
|
||||||
|
|
||||||
r.GET("/-/healthy", func(c *fasthttp.RequestCtx) {
|
|
||||||
code := fasthttp.StatusOK
|
|
||||||
msg := "healthy"
|
|
||||||
|
|
||||||
if err := a.pool.unhealthy.Load(); err != nil {
|
|
||||||
msg = "unhealthy: " + err.Error()
|
|
||||||
code = fasthttp.StatusBadRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Response.Reset()
|
|
||||||
c.SetStatusCode(code)
|
|
||||||
c.SetContentType(defaultContentType)
|
|
||||||
c.SetBodyString(defaultHealthyMsg + msg)
|
|
||||||
})
|
|
||||||
|
|
||||||
// enable metrics
|
// enable metrics
|
||||||
if v.GetBool("metrics") {
|
if v.GetBool("metrics") {
|
||||||
l.Info("enabled /metrics")
|
l.Info("enabled /metrics")
|
||||||
r.GET("/metrics/", metricsHandler(prometheus.DefaultGatherer, http.HandlerOpts{
|
attachMetrics(r, z)
|
||||||
ErrorLog: z.(http.Logger),
|
|
||||||
//ErrorHandling: 0,
|
|
||||||
//Registry: nil,
|
|
||||||
//DisableCompression: false,
|
|
||||||
//MaxRequestsInFlight: 0,
|
|
||||||
//Timeout: 0,
|
|
||||||
//EnableOpenMetrics: false,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable pprof
|
// enable pprof
|
||||||
if v.GetBool("pprof") {
|
if v.GetBool("pprof") {
|
||||||
l.Info("enabled /debug/pprof")
|
l.Info("enabled /debug/pprof")
|
||||||
r.GET("/debug/pprof/", pprofHandler())
|
attachProfiler(r)
|
||||||
r.GET("/debug/pprof/:name", pprofHandler())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
en := &fasthttp.Server{
|
en := &fasthttp.Server{
|
||||||
|
|
Loading…
Reference in a new issue