first commit
This commit is contained in:
24
apps/api/internal/validator/error_messages.go
Normal file
24
apps/api/internal/validator/error_messages.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package validator
|
||||
|
||||
// 定义自定义错误消息
|
||||
var customMessages = map[string]string{
|
||||
"Name.min": "name 不能少于1个字",
|
||||
"Name.required": "name 是必填项",
|
||||
"Name.validName": "name 只能包含中文字符",
|
||||
"MobileNo.required": "mobile_no 是必填项",
|
||||
"MobileNo.min": "mobile_no 电话号码必须为有效的中国电话号码",
|
||||
"MobileNo.max": "mobile_no 电话号码必须为有效的中国电话号码",
|
||||
"MobileNo.validMobileNo": "电话号码必须为有效的中国电话号码",
|
||||
"ID.required": "id_card 是必填项",
|
||||
"ID.validID": "id 必须为有效的身份证号码",
|
||||
"TimeRange.validTimeRange": "time_range 必须为1到5的数字,表示年",
|
||||
}
|
||||
|
||||
// 获取自定义错误消息
|
||||
func GetErrorMessage(field, tag string) string {
|
||||
key := field + "." + tag
|
||||
if msg, exists := customMessages[key]; exists {
|
||||
return msg
|
||||
}
|
||||
return "请输入正确格式的参数"
|
||||
}
|
||||
Reference in New Issue
Block a user