// swagger包以及版本
github.com/go-openapi/swag v0.19.15 // indirect
github.com/swaggo/files v1.0.0 // indirect
github.com/swaggo/gin-swagger v1.5.3 // indirect
github.com/swaggo/swag v1.8.10 // indirect
import (
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
func InitRouter(router *gin.Engine) {
rootRoute := router.Group("api")
rootRoute.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
RegisterProjectRoute(rootRoute)
}
注意点:
swag init
提示无命令,需要配置swag的环境变量,一般是go env中的GOPATHswag init
生成swagger文件会报错,需要`swag init --parseDependency -g 入口main文件_ "foo/docs"
注意下划线必加