GO遇到的坑
Posted 一曲长歌一剑天涯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GO遇到的坑相关的知识,希望对你有一定的参考价值。
1.不能传0值
type reqPostProcess struct {
ProjectID int64 `json:"project_id" binding:"required,gte=1" example:"10"`
JobID int64 `json:"job_id" binding:"required,gte=1" example:"10"`
ShowType int `json:"show_type" binding:"required" example:"3"`
CurScalarIndex int `json:"cur_scalarIndex" binding:"required" example:"0"`
ContourEnable bool `json:"contour_enable" binding:"required" example:"false"`
}
报错:
[Key: \'reqPostProcess.CurScalarIndex\' Error:Field validation for \'CurScalarIndex\' failed on the \'required\' tag]
正确的写法
type reqPostProcess struct {
ProjectID int64 `json:"project_id" binding:"required,gte=1" example:"10"`
JobID int64 `json:"job_id" binding:"required,gte=1" example:"10"`
ShowType *int `json:"show_type" binding:"required" example:"3"`
CurScalarIndex *int `json:"cur_scalarIndex" binding:"required" example:"0"`
ContourEnable bool `json:"contour_enable" binding:"required" example:"false"`
}
以上是关于GO遇到的坑的主要内容,如果未能解决你的问题,请参考以下文章