package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
type user struct {
Name string `json:"name" binding:"required"`
Email string `json:"email" binding:"required,email"`
}
type data struct {
User []user `json:"user" binding:"required,dive"` // use dive tag
}
//GetDataTest will get test data
func GetDataTest(c *gin.Context) {
var data data
err := c.Bind(&data)
if err == nil {
fmt.Printf("%+v", data)
c.JSON(http.StatusOK, gin.H{
"message": "done",
})
} else {
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
}
}
func main(){
route := gin.Default()
route.POST("/", GetDataTest)
route.Run(":8080")
}
https://blog.csdn.net/private66/article/details/82424743
标签:slice,dive,required,binding,子结构,gin,data,GetDataTest From: https://www.cnblogs.com/cheyunhua/p/17977517