Golang Gin Project using Swagger

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.