Golang Gin Project using Swagger
tags (space delimited): Go
First need github.com/swaggo/gin-swagger
and github.com/swaggo/gin-swagger/swaggerFiles
(see Gin-swagger).
The Swag tool is then obtained according to the Github.com/swaggo/swag/cmd/swag document, and the swag init
build folder is executed under the project root directory docs
. Then in the route import _ "/docs"
. This is the time to compile the program and open http://localhost:8080/swagger/index.html
it to see the API. Sometimes open the page JS error, more refresh several times have (reason unknown).
Note that the project directory, package dependencies can not use the name SRC, please see the following source code:
//exclude vendor folderif ext := filepath.Ext(path); ext == ".go" && !strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+"vendor"+string(os.PathSeparator)) && !strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".history"+string(os.PathSeparator)) && !strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".idea"+string(os.PathSeparator)) && !strings.Contains(string(os.PathSeparator)+path, string(os.PathSeparator)+".git"+string(os.PathSeparator)) { fset := token.NewFileSet() // positions are relative to fset astFile, err := goparser.ParseFile(fset, path, nil, goparser.ParseComments)
The Swag tool excludes files from,,, and vendor
.history
.idea
.git
directories (see PL). You can use tools such as GODEP to place dependency packages under the vendor directory.
Golang Gin Project using Swagger