refactor: made logger a dependency

This commit is contained in:
2025-06-20 16:52:52 +03:00
parent 7ad1336c88
commit 8007b11731
3 changed files with 40 additions and 13 deletions

View File

@@ -13,18 +13,21 @@
package main
import (
"time"
"net/http"
"context"
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
"go.uber.org/fx"
"easywish/config"
docs "easywish/docs"
"easywish/internal/controllers"
"easywish/internal/logger"
"easywish/internal/routes"
"easywish/internal/services"
docs "easywish/docs"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
@@ -35,26 +38,24 @@ func main() {
panic(err)
}
defer logger.Sync()
fx.New(
services.Module,
fx.Provide(
logger.NewLogger,
gin.Default,
controllers.NewAuthController,
controllers.NewServiceController,
),
services.Module,
controllers.Module,
routes.Module,
fx.Invoke(func(lc fx.Lifecycle, router *gin.Engine) {
// Swagger
docs.SwaggerInfo.Schemes = []string{"http"}
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
// Gin
server := &http.Server{
Addr: ":8080",
Addr: fmt.Sprintf(":%s", config.GetConfig().Port),
Handler: router,
}