Gin参数绑定

奇怪问题 #

type BugReportParam struct {
	Desc     string   `json:"desc"`	
	Stack    string   `json:"stack"`
	Function string   `json:"function"`
	Contact  string   `json:"contact"`
	Email    string   `json:"email"`
	ExtFiles []string `json:"extFiles"`
}
// BugReport godoc
//
//	@Description	日志反馈
//	@Tags			bug_Report
//	@Accept			json
//	@Produce		json
//	@Param			body	body		param.BugReportParam	true	"日志反馈参数"
//	@Success		200		{object}	response.Response
//	@Failure		500		{object}	response.Response
//	@Router			/bugreport [post]
func (r BugReport) BugReport(c *gin.Context) {
	var par param.BugReportParam
	if err := c.BindJSON(&par); err != nil {
		response.ErrorParam(c, err.Error())
		return
	}
}

入参全部是小写可以绑定 全部是大写也可以绑定 ,有大有小 也可以绑定

{
    "Desc":"222222222",
    "contact": "1",
    "Email": "tianzhiwei@forensix.cn",
    "extfiles": ["888"],
    "desc": "111111111111111"
}
type BugReportParam struct {
	desc     string   `json:"desc"`
	
	stack    string   `json:"stack"`
	
	function string   `json:"function"`
	
	contact  string   `json:"contact"`
	
	email    string   `json:"email"`
	
	extFiles []string `json:"extFiles"`

}

这里换成小写后无法绑定,我也不知道为什么 BindJSON换成ShouldBind是一样的效果