【GO】遇到的坑 - Go语言中文社区

【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"`
}
版权声明:本文来源Segmentfault,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://segmentfault.com/a/1190000040054723
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-06-13 14:10:02
  • 阅读 ( 544 )
  • 分类:Go

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢