type Detail struct {
  ID string `json:"id" form:"id" binding:"required"`
}

var req *Detail
if err := c.ShouldBind(&req); err != nil {
    return
}

if use form request and don't send any parameter, it will panic with reflect: call of reflect.Value.Interface on zero Value inside validate since the root is nil; and this works fine

var req Detail
if err := c.ShouldBind(&req); err != nil {
    return
}

Comment From: shushenghong

https://github.com/gin-gonic/gin/blob/a889c58de78711cb9b53de6cfcc9272c8518c729/binding/form_mapping.go#L88-L102

the reason is line 99, if not set any fields, it won't init the empty pointer. this is necessary for struct fields with pointer type, but not for the root struct itself