未对输入数据进行校验
YouDail opened this issue · 1 comments
YouDail commented
根据id查询学院的接口, /api/v1/departments, 未对 id 值进行校验,请求如 http://127.0.0.1:3000/api/v1/departments/-,会继续查询数据库并退出程序,fix如下:
// 对已经转换的string再尝试反转换成float64,防止输入非整数数据
_, erro := strconv.ParseFloat(id, 64)
if erro != nil {
result = gin.H{
"status": "failed",
"data": "参数错误",
}
c.JSON(http.StatusBadRequest, result)
return
}