package main
import (
"github.com/gin-gonic/gin"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
"net/http"
_ "t2/docs"
)
func main() {
r := gin.Default()
app := r.Group("/app")
app.GET("/index", appIndex)
app.GET("/tab", tabIndex)
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.Run(":8081")
}
// @Summary 打印测试功能
// @title Swagger Example API
// @version 0.0.1
// @Tags 仓s库api
// @description This is a sample server Petstore server.
// @BasePath /api/v1
// @Host 127.0.0.1:8080
// @Produce json
// @Param name body int true "Name"
// @Success 200 {string} json "{"code":200,"data":"name","msg":"ok"}"
// @Router /print [get]
func appIndex(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"msg": "请求成功appIndex!",
})
}
// @Summary 仓库已发货数据
// @Description 获取仓库数据
// @Tags 仓库api
// @Success 200 {string} json "{"msg":"success"}"
// @Router /app/index [get]
func tabIndex(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"msg": "请求成功tabIndex!",
})
}
编译
swag init
go run main.go