github address: https: //github.com/swaggo/gin-swagger
Cmd first download pack to perform relevant command
go get -u github.com/swaggo/swag/cmd/swag
I have started do not succeed, then enter the $ GOPATH / bin / directory execution go get github.com/swaggo/swag/cmd/swag, swag.exe generate a file in the bin directory, the $ GOPATH / bin / is added to the Path environment variables to be successful
Example:
package main import ( _ "apiwendang/docs" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" //_ "github.com/swaggo/gin-swagger/example/basic/docs" // docs is generated by Swag CLI, you have to import it. ) // @title AAA // @version 1.0 // @description This is a sample server Petstore server. // @termsOfService http://swagger.io/terms/ // @contact.name API Support // @contact.url http://www.swagger.io/support // @contact.email [email protected] // @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @host 127.0.0.1 // @BasePath func main() { r := gin.New() //url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition //r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) r.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) r.GET("/", func(context *gin.Context) { context.JSON(200, gin.H{ "msg": "successed", }) }) r.Run(":9009") }
Initialize command to generate a docs folder contains three files
- docs/docs.go
- swagger.json
- swagger.yaml
====
to be continued