70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package main
|
|
|
|
// @title 58team blog backend
|
|
// @version 1.0
|
|
// @description 58team blog's backend
|
|
// @termsOfService http://swagger.io/terms/
|
|
// @contact.name API Support
|
|
// @contact.url http://www.swagger.io/support
|
|
// @contact.email support@swagger.io
|
|
// @license.name Apache 2.0
|
|
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
|
// @host localhost:8080
|
|
// @BasePath /api/v1
|
|
// @securityDefinitions.basic BasicAuth
|
|
|
|
import (
|
|
docs "58team_blog/docs"
|
|
"58team_blog/internal/application/services"
|
|
"58team_blog/internal/infrastructure"
|
|
"58team_blog/internal/infrastructure/db"
|
|
"58team_blog/internal/infrastructure/db/repo"
|
|
"58team_blog/internal/interfaces"
|
|
"log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
swaggerFiles "github.com/swaggo/files"
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
)
|
|
|
|
func main() {
|
|
router := gin.Default()
|
|
|
|
// Swagger setup
|
|
docs.SwaggerInfo.Title = "58team blog"
|
|
docs.SwaggerInfo.Description = "This is blog 58team"
|
|
docs.SwaggerInfo.Version = "1.0"
|
|
docs.SwaggerInfo.Host = "localhost:8080"
|
|
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")
|
|
|
|
// Routes setup
|
|
g := router.Group("/api/v1")
|
|
|
|
config, err := infrastructure.LoadConfig()
|
|
if err != nil {
|
|
log.Fatal("Load config error: ", err)
|
|
}
|
|
|
|
d, err := db.DatabaseInit(*config)
|
|
if err != nil {
|
|
log.Fatal("Database error: ", err)
|
|
}
|
|
postRepository := repo.CreatePostRepository(d)
|
|
|
|
postService := services.CreatePostService(&postRepository)
|
|
interfaces.BindPostAdmin(&postService, g)
|
|
|
|
router.Run(":8080")
|
|
}
|