simplify main func

This commit is contained in:
Evgeniy Kulikov 2020-03-03 13:36:52 +03:00
parent 2db83caf29
commit d0901587e2
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2

41
main.go
View file

@ -7,8 +7,6 @@ import (
"time"
"github.com/fasthttp/router"
"github.com/prometheus/client_golang/prometheus"
http "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
"google.golang.org/grpc/grpclog"
@ -21,11 +19,6 @@ type app struct {
key *ecdsa.PrivateKey
}
const (
defaultHealthyMsg = "NeoFS HTTP Gateway is "
defaultContentType = "text/plain; charset=utf-8"
)
func main() {
var (
err error
@ -52,45 +45,19 @@ func main() {
r.RedirectTrailingSlash = true
r.GET("/get/:cid/:oid", a.receiveFile)
r.GET("/-/ready", func(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusOK)
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)
})
// attaching /-/(ready,healthy)
attachHealthy(r, a.pool.unhealthy)
// enable metrics
if v.GetBool("metrics") {
l.Info("enabled /metrics")
r.GET("/metrics/", metricsHandler(prometheus.DefaultGatherer, http.HandlerOpts{
ErrorLog: z.(http.Logger),
//ErrorHandling: 0,
//Registry: nil,
//DisableCompression: false,
//MaxRequestsInFlight: 0,
//Timeout: 0,
//EnableOpenMetrics: false,
}))
attachMetrics(r, z)
}
// enable pprof
if v.GetBool("pprof") {
l.Info("enabled /debug/pprof")
r.GET("/debug/pprof/", pprofHandler())
r.GET("/debug/pprof/:name", pprofHandler())
attachProfiler(r)
}
en := &fasthttp.Server{