31 lines
855 B
Go
31 lines
855 B
Go
package api
|
|
|
|
import (
|
|
"cafe/config"
|
|
"cafe/docs"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/sirupsen/logrus"
|
|
swaggerFiles "github.com/swaggo/files"
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
)
|
|
|
|
func (a *Api) SetupSwagger() {
|
|
if config.Cafe.Swagger {
|
|
docs.SwaggerInfo.Title = "Cafe"
|
|
docs.SwaggerInfo.Description = "This is the backend of a cafe"
|
|
docs.SwaggerInfo.Version = os.Getenv("VERSION")
|
|
docs.SwaggerInfo.BasePath = "/api"
|
|
parsed, _ := url.Parse(config.Cafe.AllowedHosts[0])
|
|
docs.SwaggerInfo.Host = parsed.Host
|
|
|
|
a.Router.GET("/swagger", func(c *gin.Context) {
|
|
c.Redirect(http.StatusMovedPermanently, "/swagger/index.html")
|
|
})
|
|
a.Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
logrus.WithField("url", config.Cafe.AllowedHosts[0]+"/swagger").Info("Swagger running")
|
|
}
|
|
}
|