github.com/soulteary/pocket-bookcase@v0.0.0-20240428065142-0b5a9a0fc98a/internal/http/routes/swagger.go (about) 1 package routes 2 3 import ( 4 "github.com/gin-gonic/gin" 5 "github.com/sirupsen/logrus" 6 "github.com/soulteary/pocket-bookcase/internal/model" 7 swaggerfiles "github.com/swaggo/files" 8 ginSwagger "github.com/swaggo/gin-swagger" 9 10 _ "github.com/soulteary/pocket-bookcase/docs/swagger" 11 ) 12 13 type SwaggerAPIRoutes struct { 14 logger *logrus.Logger 15 } 16 17 func (r *SwaggerAPIRoutes) Setup(g *gin.RouterGroup) model.Routes { 18 g.Use(func(c *gin.Context) { 19 if c.Request.URL.Path == "/swagger" || c.Request.URL.Path == "/swagger/" { 20 c.Redirect(302, "/swagger/index.html") 21 return 22 } 23 }) 24 g.GET("/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) 25 return r 26 } 27 28 func NewSwaggerAPIRoutes(logger *logrus.Logger) *SwaggerAPIRoutes { 29 return &SwaggerAPIRoutes{ 30 logger: logger, 31 } 32 }