我看网上很多关于golang gin整合swagger的教程,但都写的比较模糊,所以我自己整理了一个golang引入swagger的教程,希望能帮到大家。
1.安装swagger的cmd命令
go install github.com/swaggo/swag/cmd/swag@latest
2.需要将通用API注释写在main.go
中
package main
import (
"docs"
swaggerFiles "github.com/swaggo/files" // swagger embed files
ginSwagger "github.com/swaggo/gin-swagger" // gin-swagger middleware
)
// @title Chop a Sabre API
// @version 1.0
// @description Interface document of Chop a Sabre.
// @termsOfService http://swagger.io/terms/
// @contact.name To be named
// @contact.url Undetermined
// @contact.email Undetermined
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /api/v1
// @securityDefinitions.basic BasicAuth
fu