package main import ( "github.com/gin-gonic/gin" ginSwagger "github.com/swaggo/gin-swagger" swaggerFiles "github.com/swaggo/files" "net/http" _ "standard/swagger/docs" ) // @title swagger使用例子 // @version 1.0 // @description swagger 入门使用例子 func main() { r := gin.Default() r.GET("/check", connectCheck) r.POST("/test", test) r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) r.Run(":8080") } type Response struct { Code uint32 `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` } type ResponseError struct { Code uint32 `json:"code"` Message uint32 `json:"message"` } // @summary 服务连接校验 // @Description 服务初始连接测试 // @Accept json // @Produce json // Success 200 {object} Response // Failure 400 {object} ResponseError // Failure 404 {object} ResponseError // Failure 500 {object} ResponseError // @Router /check [get] func connectCheck(c *gin.Context) { res := Response{Code: 1001, Message: "OK", Data: "connect success !!!"} c.JSON(http.StatusOK, res) } // @summary 服务连接校验 // @Description 服务初始连接测试 // @Accept json // @Produce json // Success 200 {object} Response // Failure 400 {object} ResponseError // Failure 404 {object} ResponseError // Failure 500 {object} ResponseError // @Router /check [get] func test(c *gin.Context){ }