package main
import"github.com/gin-gonic/gin"type User struct{
ID string`form:"id" binding:"required"`
Name string`form:"name" binding:"required,min=3,max=7"`}//测试:funcmain(){
r:=gin.Default()
r.POST("user",func(context *gin.Context){
var user User
if err:=context.ShouldBind(&user);err !=nil{
context.JSON(500,gin.H{
"Code":500,"Msg":err.Error(),})return}
context.JSON(200,gin.H{
"Code":200,"User":user,})})
r.Run()}
测试
###发送post请求模拟Form表单
POST http://localhost:8080/user/
Content-Type: application/x-www-form-urlencoded
id=111&name=zhangsa