1 Star 1 Fork 0

kade/library

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
swagger.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
kade 提交于 2024-03-25 15:24 . 补充细节
package swaggo
import (
"gitee.com/go-kade/library/ioc"
"gitee.com/go-kade/library/ioc/apps/apidoc"
"gitee.com/go-kade/library/ioc/config/http"
"gitee.com/go-kade/library/ioc/config/log"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/swaggo/swag"
)
func init() {
ioc.Api().Registry(&SwaggerApiDoc{
ApiDoc: apidoc.ApiDoc{},
InstanceName: "swagger",
})
}
type SwaggerApiDoc struct {
ioc.ObjectImpl
log *zerolog.Logger
apidoc.ApiDoc
InstanceName string `json:"instance_name" yaml:"instance_name" toml:"instance_name" env:"SWAGGER_INSTANCE_NAME"`
}
func (h *SwaggerApiDoc) Name() string {
return apidoc.AppNamegin
}
func (h *SwaggerApiDoc) Init() error {
h.log = log.Sub("api_doc")
return nil
}
func (i *SwaggerApiDoc) Priority() int {
return -101
}
func (h *SwaggerApiDoc) Meta() ioc.ObjectMeta {
meta := ioc.DefaultObjectMeta()
meta.CustomPathPrefix = h.Path
return meta
}
func (h *SwaggerApiDoc) Registry(r gin.IRouter) {
r.GET("/", func(c *gin.Context) {
c.Writer.WriteString(swag.GetSwagger(h.InstanceName).ReadDoc())
})
h.log.Info().Msgf("Get the API Doc using %s", http.Get().ApiObjectAddr(h))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-kade/library.git
git@gitee.com:go-kade/library.git
go-kade
library
library
v1.1.3

搜索帮助