changes...

This commit is contained in:
KamilM1205 2025-09-22 22:12:49 +04:00
parent 41944884b4
commit ab4b53fd40
26 changed files with 600 additions and 51 deletions

View file

@ -20,9 +20,12 @@ import (
"58team_blog/internal/infrastructure/db"
"58team_blog/internal/infrastructure/db/repo"
"58team_blog/internal/interfaces"
"58team_blog/internal/utils"
"log"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
@ -30,6 +33,11 @@ import (
func main() {
router := gin.Default()
// Register custom validators
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
v.RegisterValidation("password", utils.PasswordValidator)
}
// Swagger setup
docs.SwaggerInfo.Title = "58team blog"
docs.SwaggerInfo.Description = "This is blog 58team"
@ -38,14 +46,6 @@ func main() {
docs.SwaggerInfo.BasePath = "/api/v1/"
docs.SwaggerInfo.Schemes = []string{"http", "https"}
// router.GET("/swagger/*any", func(c *gin.Context) {
// path := c.Param("any")
// if strings.HasPrefix(path, "/doc.json") {
// c.File("docs/swagger.json")
// } else {
//
// }
// })
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.URL("http://localhost:8080/swag/doc/doc.json")))
router.StaticFile("/swag/doc/doc.json", "docs/swagger.json")
@ -61,10 +61,15 @@ func main() {
if err != nil {
log.Fatal("Database error: ", err)
}
postRepository := repo.CreatePostRepository(d)
userRepository := repo.CreateUserRepository(d)
postService := services.CreatePostService(&postRepository)
userService := services.CreateUserService(&userRepository)
interfaces.BindPostAdmin(&postService, g)
interfaces.BindUser(&userService, g)
router.Run(":8080")
}