update
This commit is contained in:
		
							
								
								
									
										49
									
								
								run.go
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								run.go
									
									
									
									
									
								
							@ -114,13 +114,42 @@ func getDataStatus(val gjson.Result, dataType string) string {
 | 
			
		||||
	return ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// formatInputVal ...
 | 
			
		||||
//
 | 
			
		||||
// Author : go_developer@163.com<白茶清欢>
 | 
			
		||||
//
 | 
			
		||||
// Date : 18:02 2024/5/2
 | 
			
		||||
func formatInputVal(val gjson.Result, rule *define.FieldRule) (any, error) {
 | 
			
		||||
	inputVal := val.Value()
 | 
			
		||||
	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
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return inputVal, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// validate 验证字段
 | 
			
		||||
//
 | 
			
		||||
// Author : go_developer@163.com<白茶清欢>
 | 
			
		||||
//
 | 
			
		||||
// Date : 14:32 2024/4/29
 | 
			
		||||
func validate(sourceData []byte, val gjson.Result, rule *define.FieldRule) (any, error) {
 | 
			
		||||
	inputVal := val.Value()
 | 
			
		||||
	var (
 | 
			
		||||
		err      error
 | 
			
		||||
		inputVal any
 | 
			
		||||
	)
 | 
			
		||||
	if !val.Exists() {
 | 
			
		||||
		if rule.IsRequired {
 | 
			
		||||
			return nil, fmt.Errorf("%v : field is required, but not found", rule.Path)
 | 
			
		||||
@ -128,24 +157,10 @@ func validate(sourceData []byte, val gjson.Result, rule *define.FieldRule) (any,
 | 
			
		||||
		// TODO : 验证有条件必传
 | 
			
		||||
		inputVal = rule.DefaultValue
 | 
			
		||||
	} else {
 | 
			
		||||
		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
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		if inputVal, err = formatInputVal(val, rule); nil != err {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return handleData(inputVal, rule)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user