-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject.go
More file actions
34 lines (26 loc) · 769 Bytes
/
inject.go
File metadata and controls
34 lines (26 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package ginx
import (
"github.com/gin-gonic/gin"
"github.com/swaggo/swag"
"github.com/xiaoshicae/ginx/options"
"github.com/xiaoshicae/ginx/swagger"
"github.com/xiaoshicae/xone"
)
func injectSwaggerInfo(swaggerInfo *swag.Spec, engine *gin.Engine, opts ...options.SwaggerOption) {
if swaggerInfo == nil || engine == nil {
return
}
engine.FuncMap[xone.SwaggerInfoFuncKey] = func() *swag.Spec { return swaggerInfo }
dso := options.DefaultSwaggerOptions()
for _, opt := range opts {
opt(dso)
}
swaggerUrl := swagger.SwaggerUrl
if dso.UrlPrefix != "" {
swaggerUrl = dso.UrlPrefix + swaggerUrl
}
engine.GET(swaggerUrl, swagger.SwaggerHandler)
}
func injectPrintBanner(engine *gin.Engine) {
engine.FuncMap[xone.PrintBannerFuncKey] = PrintBanner
}