frostfs-rest-gw/cmd/neofs-rest-gw/main.go
Denis Kirillov 6f789f149e [#71] Validate config for unknown keys
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2022-11-10 11:30:06 +03:00

49 lines
1.1 KiB
Go

package main
import (
"context"
"os/signal"
"syscall"
"github.com/go-openapi/loads"
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi"
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
"go.uber.org/zap"
)
func main() {
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
v := config()
logger := newLogger(v)
validateConfig(v, logger)
neofsAPI, err := newNeofsAPI(ctx, logger, v)
if err != nil {
logger.Fatal("init neofs", zap.Error(err))
}
swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal("init spec", zap.Error(err))
}
serverCfg := serverConfig(v)
serverCfg.SuccessfulStartCallback = neofsAPI.StartCallback
api := operations.NewNeofsRestGwAPI(swaggerSpec)
server := restapi.NewServer(api, serverCfg)
defer func() {
if err = server.Shutdown(); err != nil {
logger.Error("shutdown", zap.Error(err))
}
}()
server.ConfigureAPI(neofsAPI.Configure)
neofsAPI.RunServices()
// serve API
if err = server.Serve(); err != nil {
logger.Fatal("serve", zap.Error(err))
}
}