字符串验证 : 支持配置参数传了的场景下,不允许为空验证

This commit is contained in:
2024-11-01 17:22:41 +08:00
parent e5b2e1a377
commit c35d379a26
2 changed files with 69 additions and 1 deletions

View File

@ -116,6 +116,11 @@ func handleString(inputVal any, rule *define.FieldRule) (string, error) {
if err = util.ConvertAssign(&formatData, inputVal); nil != err {
return "", err
}
// 判断空字符串
if !rule.AllowEmpty && formatData == "" && rule.IsRequired {
// 必传且不允许空字符串
return "", fmt.Errorf("%v : data type is string empty, field is required and empty value is not allowed", rule.Path)
}
if nil == rule.ValueLimit {
return formatData, nil
}