changes...
This commit is contained in:
parent
41944884b4
commit
ab4b53fd40
26 changed files with 600 additions and 51 deletions
21
cmd/main.go
21
cmd/main.go
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue