Files
tp/main_dc/BB/api_bb/cmd/main.go
T
valitovgaziz 15357fd3c0 create and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarbacreate and moove into new directories for BegushiyBashkir and
yalarba
2025-10-24 05:22:44 +05:00

64 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// main.go с graceful shutdown
package main
import (
"log"
"os"
"os/signal"
"syscall"
"api_bb/internal/app"
"api_bb/internal/config"
"api_bb/pkg/logger"
"go.uber.org/zap"
)
func main() {
// Загрузка конфигурации
cfg := config.Load()
// Инициализация логгера
if err := logger.Init(
os.Getenv("LOG_LEVEL"),
os.Getenv("ENVIRONMENT"),
); err != nil {
log.Printf("Failed to initialize logger: %v", err)
os.Exit(1)
}
defer logger.Sync()
// Логируем начало работы
logger.LogApplicationStart(os.Getenv("REST_API_VERSION"), os.Getenv("ENVIRONMENT"), "")
// Создание и инициализация приложения
application := app.NewApp(cfg)
if err := application.Initialize(); err != nil {
logger.Get().Fatal("failed to initialize application", zap.Error(err))
}
// Канал для graceful shutdown
done := make(chan bool, 1)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
// Запуск сервера в горутине
go func() {
if err := application.Start(); err != nil {
logger.Get().Fatal("failed to start server", zap.Error(err))
}
done <- true
}()
// Ожидание сигнала shutdown
<-quit
logger.Get().Info("shutdown signal received")
// Graceful shutdown приложения
if err := application.Shutdown(); err != nil {
logger.Get().Fatal("could not gracefully shutdown the application", zap.Error(err))
}
logger.LogApplicationShutdown("graceful shutdown")
<-done
}