fix: direct swaggerFiles.Handler with path stripping
Some checks failed
CI / Build & Test (push) Has been cancelled
Some checks failed
CI / Build & Test (push) Has been cancelled
This commit is contained in:
parent
434dbcc7fa
commit
d2440c5c67
@ -8,13 +8,24 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
|
||||||
swaggerFiles "github.com/swaggo/files"
|
swaggerFiles "github.com/swaggo/files"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SwaggerHandler() gin.HandlerFunc {
|
func SwaggerHandler() gin.HandlerFunc {
|
||||||
return ginSwagger.WrapHandler(swaggerFiles.Handler)
|
return func(c *gin.Context) {
|
||||||
|
rawPath := c.Request.URL.Path
|
||||||
|
relPath := strings.TrimPrefix(rawPath, "/swagger")
|
||||||
|
if relPath == "" || relPath == "/" {
|
||||||
|
c.Request.URL.Path = "/index.html"
|
||||||
|
} else {
|
||||||
|
c.Request.URL.Path = relPath
|
||||||
|
}
|
||||||
|
|
||||||
|
swaggerFiles.Handler.ServeHTTP(c.Writer, c.Request)
|
||||||
|
|
||||||
|
c.Request.URL.Path = rawPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SwaggerCSSBranding() gin.HandlerFunc {
|
func SwaggerCSSBranding() gin.HandlerFunc {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user