diff --git a/run.go b/run.go index 6f58b73..b060c28 100644 --- a/run.go +++ b/run.go @@ -84,12 +84,12 @@ func RunWithResult(sourceData map[string]any, ruleList []*define.FieldRule) ([]b // 通过有条件必传, 填充 is_required checkRuleConditionRequiredRule(byteData, itemRule) inputFieldVal := gjson.GetBytes(byteData, itemRule.Path) - if formatRule, err := validate(byteData, inputFieldVal, itemRule); nil != err { + if formatValue, err := validate(byteData, inputFieldVal, itemRule); nil != err { return nil, err } else { if !itemRule.DisableRewrite { // 更新数据 - byteData, _ = sjson.SetBytes(byteData, itemRule.Path, formatRule) + byteData, _ = sjson.SetBytes(byteData, itemRule.Path, formatValue) } } } @@ -219,10 +219,14 @@ func validate(sourceData []byte, val gjson.Result, rule *define.FieldRule) (any, inputVal any ) - if !val.Exists() { + if !val.Exists() || nil == val.Value() { if rule.IsRequired { return nil, fmt.Errorf("%v : field is required, but not found", rule.Path) } + if strings.HasSuffix(rule.Type, "_ptr") { + // 指针类型数据, 无需验证 + return nil, nil + } inputVal = rule.DefaultValue } else { if inputVal, err = formatInputVal(val, rule); nil != err {