看看啥问题了
package main import ( "github.com/gin-gonic/gin" "net/http" ) type Person struct { name string `from:"name"` age int `from:"age"` } func main() { r:=gin.Default() r.GET("test", testing) r.POST("test", testing) r.Run() } func testing(c *gin.Context) { var person Person if err:=c.ShouldBind(&person); err == nil{ c.String(http.StatusOK,"OK %v",person) }else{ c.String(http.StatusBadRequest,"No %v",err) } }
返回了
OK { 0}