【Golang】Swagger报错:not yet registered swag
根据官方github的Usage,安装和使用Swagger需要以下几步:
- 安装swag
- 初始化
- 安装gin-swagger
- 编写注释
但是有的Gopher写到这里就完事了。
如果这样,你的丝袜哥应该会报错。
"not yet registered swag"
为啥呢?
官方说的很清楚:
import (
...
_ "github.com/swaggo/gin-swagger/example/basic/docs" // docs is generated by Swag CLI, you have to import it.
)
怎么解决呢
导入自己的docs包/文件夹
import (
...
_ "github.com/swaggo/gin-swagger/example/basic/docs"
)
看看你docs.go文件里的import是不是有爆红?
docs/docs.go
“github.com/alecthomas/template” //此处应该是红色
如果是爆红了,go get一下就好了:
$ go get "github.com/alecthomas/template"
如果没爆红的话,应该走完第一步就好了。
以上是我个人错误的记录。仅供参考。
多看官方文档!
还没有评论,来说两句吧...