type HcStatus struct {
Name string `json:"name" binding:"required"`
IsAlert int `json:"isalert" binding:"required"`
}
func UpdateStatus(c *gin.Context) {
var inputs HcStatus
err := c.Bind(&inputs)
fmt.Println("error:====>",err)
}
when the IsAlert bigger than 0, it will be correct. But the alert is 0, it will be Key: 'HcStatus.IsAlert' Error:Field validation for 'IsAlert' failed on the 'required' tag.
sorry,I am a newbie. How can I resolve it?
The message says the reason itself. You specified the "required" constraint to the param IsAlert, and it means IsAlert must have values except the zero value -- 0 for int.
If you want to permit 0 for IsAlert, you should not use "required" for IsAlert.
@delphinus ok,thanks.