2022-04-11 09:35:06 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-10 09:39:35 +00:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2022-04-11 09:35:06 +00:00
|
|
|
|
|
|
|
"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() {
|
2022-10-10 09:39:35 +00:00
|
|
|
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
2022-04-11 09:35:06 +00:00
|
|
|
|
|
|
|
v := config()
|
|
|
|
logger := newLogger(v)
|
2022-10-21 13:53:30 +00:00
|
|
|
validateConfig(v, logger)
|
2022-04-11 09:35:06 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2022-08-11 14:07:53 +00:00
|
|
|
serverCfg := serverConfig(v)
|
|
|
|
serverCfg.SuccessfulStartCallback = neofsAPI.StartCallback
|
|
|
|
|
2022-04-11 09:35:06 +00:00
|
|
|
api := operations.NewNeofsRestGwAPI(swaggerSpec)
|
2022-08-11 14:07:53 +00:00
|
|
|
server := restapi.NewServer(api, serverCfg)
|
2022-04-11 09:35:06 +00:00
|
|
|
defer func() {
|
|
|
|
if err = server.Shutdown(); err != nil {
|
|
|
|
logger.Error("shutdown", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
server.ConfigureAPI(neofsAPI.Configure)
|
2022-08-11 14:07:53 +00:00
|
|
|
neofsAPI.RunServices()
|
2022-04-11 09:35:06 +00:00
|
|
|
|
|
|
|
// serve API
|
|
|
|
if err = server.Serve(); err != nil {
|
|
|
|
logger.Fatal("serve", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|