separate for to servers user and admin controllers

This commit is contained in:
Pavel 2024-05-29 11:28:25 +03:00
parent 3b780b9054
commit ff445db1a6
6 changed files with 27 additions and 11 deletions

@ -98,17 +98,29 @@ func Run(cfg *config.Config, build Build) {
CustomerServiceHost: cfg.CustomerRPCHost,
}))
httpSrv := server.NewHTTP(server.ServerConfig{
userSrv := server.NewHTTP(server.ServerConfig{
Logger: logger,
Controllers: []server.Controller{cons.VerificationUser, cons.VerificationAdmin},
Controllers: []server.Controller{cons.VerificationUser},
HLogger: loggerHlog,
})
adminSrv := server.NewHTTP(server.ServerConfig{
Logger: logger,
Controllers: []server.Controller{cons.VerificationAdmin},
HLogger: loggerHlog,
})
go func() {
if err := httpSrv.Start(cfg.HttpAddress); err != nil {
if err := userSrv.Start(cfg.HttpAddressUser); err != nil {
logger.Fatal("Server startup error", zap.Error(err))
}
}()
gracefulShutdown(ctx, logger, httpSrv, mongoDB)
go func() {
if err := adminSrv.Start(cfg.HttpAddressAdmin); err != nil {
logger.Fatal("Server startup error", zap.Error(err))
}
}()
gracefulShutdown(ctx, logger, []*server.Server{userSrv, adminSrv}, mongoDB)
}

@ -10,7 +10,7 @@ import (
"syscall"
)
func gracefulShutdown(ctx context.Context, logger *zap.Logger, httpSrv *server.Server, mongoDB *mongo.Database) {
func gracefulShutdown(ctx context.Context, logger *zap.Logger, httpSrvs []*server.Server, mongoDB *mongo.Database) {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
killSignal := <-interrupt
@ -21,9 +21,11 @@ func gracefulShutdown(ctx context.Context, logger *zap.Logger, httpSrv *server.S
logger.Info("AppTerminated")
}
if err := httpSrv.Shutdown(ctx); err != nil {
for _, srv := range httpSrvs {
if err := srv.Shutdown(ctx); err != nil {
logger.Error("HttpServerShutdown", zap.Error(err))
}
}
if err := mongoDB.Client().Disconnect(ctx); err != nil {
logger.Error("MongoDB", zap.Error(err))

@ -8,7 +8,8 @@ import (
type Config struct {
TelegramToken string `env:"TELEGRAM_TOKEN,required"`
TelegramChannelID int64 `env:"TELEGRAM_CHANNEL_ID,required"`
HttpAddress string `env:"HTTP_ADDRESS,required"`
HttpAddressUser string `env:"HTTP_ADDRESS_USER,required"`
HttpAddressAdmin string `env:"HTTP_ADDRESS_ADMIN,required"`
MongoHost string `env:"MONGO_HOST,required"`
MongoPort string `env:"MONGO_PORT,required"`
MongoUser string `env:"MONGO_USER,required"`

Binary file not shown.

@ -1,6 +1,7 @@
TELEGRAM_TOKEN=6712573453:AAFbioUuXf0Te73MUCqa0_h09qEQ1iQREas
TELEGRAM_CHANNEL_ID=542073142
HTTP_ADDRESS=0.0.0.0:8080
HTTP_ADDRESS_USER=0.0.0.0:8080
HTTP_ADDRESS_ADMIN=0.0.0.0:8081
MONGO_HOST=localhost
MONGO_PORT=27020
MONGO_USER=test

@ -11,7 +11,7 @@ import (
)
func Test_GetVerifyAdmin(t *testing.T) {
url := "http://localhost:8080/verification/64e53ed187392e122e5d3d50"
url := "http://localhost:8081/verification/64e53ed187392e122e5d3d50"
client := fiber.AcquireClient()
token, err := helpers.CreateJwt("64e53ed187392e122e5d3d51")
@ -31,7 +31,7 @@ func Test_GetVerifyAdmin(t *testing.T) {
assert.NoError(t, err)
fmt.Println(resp)
url = "http://localhost:8080/verification"
url = "http://localhost:8081/verification"
client2 := fiber.AcquireClient()
req := models.ReqSetVerification{