V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  qh666  ›  全部回复第 1 页 / 共 1 页
回复总数  2
59 天前
回复了 Geekerstar 创建的主题 Java javafx 打包 exe 问题
gopher 看到这种问题太爽了
使用 https://github.com/go-playground/validator 校验即可
类似于这种接第三方 api 的应用推荐使用
github.com/go-resty/resty

个人建议是早期先引入此类成熟的工具库,否则后期不好改动,只能硬着头皮去维护了

参考

validated.BindAndValidatePostJson()

type LoginReq struct {
Phone string `json:"phone" binding:"omitempty,required_if=Type 1,required_if=Type 2,phone,len=11"` // 手机号
Type int `json:"type" binding:"required,oneof=1 2 3 4"` // 1 短信验证码登录 2 账号密码登录
}
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   950 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 69ms · UTC 19:43 · PVG 03:43 · LAX 12:43 · JFK 15:43
Developed with CodeLauncher
♥ Do have faith in what you're doing.