Init
This commit is contained in:
commit
f90fdc0598
99 changed files with 15260 additions and 0 deletions
31
api/swagger.go
Normal file
31
api/swagger.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
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")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue