1.get传参
//get请求 返回json 接口传参r.GET("/getJson/:id", controller.GetUserInfo)
1.2.接收处理
package controllerimport "github.com/gin-gonic/gin"func GetUserInfo(c *gin.Context) {_ = c.Param("id")ReturnSucess(c, 200, "sucess", "传参为:id=" +c.Param("id"), 1)}
1.3.接口测试
2.post传参
//POST请求 返回json 接口传参jsonr.POST("/postJson", controller.PostUserInfo)
2.1接受处理
package controllerimport "github.com/gin-gonic/gin"func PostUserInfo(c *gin.Context) {param := make(map[string]interface{})err := c.BindJSON(¶m)if err == nil {ReturnSucess(c, 200, "sucess", param, 1)return}ReturnError(c, 500, gin.H{"err": err}, param, 1)}
2.2接口测试