1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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!",
    })
}

编译

1
2
swag init
go run main.go