下载swag

go get -u github.com/swaggo/swag/cmd/swag

在test项目引入

import (
       ginSwagger "github.com/swaggo/gin-swagger"
    _ "test/docs"
    "github.com/gin-gonic/gin"
     "github.com/swaggo/gin-swagger/swaggerFiles"
)
func main(){
    api := gin.Default()
    api.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
        api.POST("/v1/api/getProductCompanys", GetProductCompanys) 
        api.Run()
}

编写适当等注释

// GetProductCompanys 获取企业基本信息
// @Summary 获取企业基本信息
// @Description 通过请求的企业类型返回企业信息
// @Accept  json
// @Produce json
// @Param type body string true "企业类型(1 大陆寿险,2 港险,10 热门企业)"
// @Success 200 {object} modles.ReturnCompany
// @Failure 500 "error"
// @Router /v1/api/GetCompanys [post]
func GetCompanys(c *gin.Context) {
      do.....
}

然后启动,访问 http://127.0.0.1:8080/swagger/index.html