ms-tester/main.go
2024-07-27 07:31:04 +00:00

48 lines
1.1 KiB
Go

package main
import (
"fmt"
"go.uber.org/zap"
"google.golang.org/grpc"
"ms-auth/internal/app"
"ms-auth/internal/lib"
"ms-auth/internal/services"
"ms-auth/internal/storage"
"ms-auth/internal/transport"
"os"
"os/signal"
"syscall"
)
func main() {
cfg := lib.MustSetupConfig()
var logger *zap.Logger
if cfg.Env == "prod" {
logger = zap.Must(zap.NewProduction())
} else if cfg.Env == "dev" {
logger = zap.Must(zap.NewDevelopment())
} else {
panic(fmt.Sprintf(`error reading config: env expected "prod" or "dev", got "%s"`, cfg.Env))
}
postgres := storage.NewUserStorage(cfg.PostgresDSN, logger)
vk := storage.NewValkeyStorage(cfg.RedisDSN, cfg, logger)
sessionService := services.NewSessionService(vk, postgres, cfg)
userService := services.NewUserService(postgres, vk, vk, cfg)
server := transport.NewAuthServer(sessionService, userService, grpc.NewServer(), logger)
application := app.NewApp(cfg, server)
application.Start()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
<-stop
application.GracefullyStop()
}