This commit is contained in:
2024-11-03 15:28:10 +08:00
commit cca66faed5
113 changed files with 4349 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package validator
// 定义自定义错误消息
var customMessages = map[string]string{
"Name.min": "姓名不能少于1个字",
"Name.required": "姓名是必填项",
"Name.name": "姓名只能包含中文",
"Mobile.required": "手机号是必填项",
"Mobile.min": "电话号码必须为有效的中国电话号码",
"Mobile.max": "电话号码必须为有效的中国电话号码",
"Mobile.mobile": "电话号码必须为有效的中国电话号码",
"IDCard.required": "身份证号是必填项",
"IDCard.idCard": "无效的身份证号码",
}
// 获取自定义错误消息
func GetErrorMessage(field, tag string) string {
key := field + "." + tag
if msg, exists := customMessages[key]; exists {
return msg
}
return "请输入正确格式的参数"
}