增加单元测试 + 修复BUG
This commit is contained in:
18
run.go
18
run.go
@ -128,11 +128,21 @@ func validate(sourceData []byte, val gjson.Result, rule *define.FieldRule) (any,
|
||||
// TODO : 验证有条件必传
|
||||
inputVal = rule.DefaultValue
|
||||
} else {
|
||||
if inputVal == nil {
|
||||
if !rule.AllowNil {
|
||||
return nil, fmt.Errorf("%v : field value is nil, but not allowed", rule.Path)
|
||||
if nil == inputVal {
|
||||
if rule.IsRequired {
|
||||
return nil, fmt.Errorf("%v : data is required, but get nil", rule.Path)
|
||||
}
|
||||
if rule.DisableAutoConvert {
|
||||
inputVal = rule.DefaultValue
|
||||
} else {
|
||||
inputVal = strings.TrimSpace(rule.DefaultValue)
|
||||
}
|
||||
} else {
|
||||
if !rule.DisableAutoConvert {
|
||||
if inputValStr, ok := inputVal.(string); ok {
|
||||
inputVal = inputValStr
|
||||
}
|
||||
}
|
||||
inputVal = rule.DefaultValue
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user