|
|
@ -192,57 +192,6 @@ func (e *FieldError) Error() string { |
|
|
|
return fmt.Sprintf(fieldErrMsg, e.Field, e.Tag) |
|
|
|
return fmt.Sprintf(fieldErrMsg, e.Field, e.Tag) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// func (e *FieldError) flatten(isFromStruct bool) map[string]*FieldError {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// errs := map[string]*FieldError{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if e.IsPlaceholderErr {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if e.IsSliceOrArray {
|
|
|
|
|
|
|
|
// for key, err := range e.SliceOrArrayErrs {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fe, ok := err.(*FieldError)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if ok {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if flat := fe.flatten(isFromStruct); flat != nil && len(flat) > 0 {
|
|
|
|
|
|
|
|
// for k, v := range flat {
|
|
|
|
|
|
|
|
// errs[fmt.Sprintf("[%#v]%s", key, k)] = v
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// se := err.(*StructErrors)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if flat := se.flatten(isFromStruct); flat != nil && len(flat) > 0 {
|
|
|
|
|
|
|
|
// for k, v := range flat {
|
|
|
|
|
|
|
|
// errs[fmt.Sprintf("[%#v].%s.%s", key, se.Struct, k)] = v
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if e.IsMap {
|
|
|
|
|
|
|
|
// // for _, err := range e.MapErrs {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // if flat := err.Flatten(); flat != nil && len(flat) > 0 {
|
|
|
|
|
|
|
|
// // for k, v := range flat {
|
|
|
|
|
|
|
|
// // errs[k] = v
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return errs
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// errs[e.Field] = e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return errs
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flatten flattens the FieldError hierarchical structure into a flat namespace style field name
|
|
|
|
// Flatten flattens the FieldError hierarchical structure into a flat namespace style field name
|
|
|
|
// for those that want/need it.
|
|
|
|
// for those that want/need it.
|
|
|
|
// This is now needed because of the new dive functionality
|
|
|
|
// This is now needed because of the new dive functionality
|
|
|
@ -273,7 +222,7 @@ func (e *FieldError) Flatten() map[string]*FieldError { |
|
|
|
|
|
|
|
|
|
|
|
se := err.(*StructErrors) |
|
|
|
se := err.(*StructErrors) |
|
|
|
|
|
|
|
|
|
|
|
if flat := se.flatten(false); flat != nil && len(flat) > 0 { |
|
|
|
if flat := se.Flatten(); flat != nil && len(flat) > 0 { |
|
|
|
for k, v := range flat { |
|
|
|
for k, v := range flat { |
|
|
|
errs[fmt.Sprintf("[%#v].%s.%s", key, se.Struct, k)] = v |
|
|
|
errs[fmt.Sprintf("[%#v].%s.%s", key, se.Struct, k)] = v |
|
|
|
} |
|
|
|
} |
|
|
@ -302,7 +251,7 @@ func (e *FieldError) Flatten() map[string]*FieldError { |
|
|
|
|
|
|
|
|
|
|
|
se := err.(*StructErrors) |
|
|
|
se := err.(*StructErrors) |
|
|
|
|
|
|
|
|
|
|
|
if flat := se.flatten(false); flat != nil && len(flat) > 0 { |
|
|
|
if flat := se.Flatten(); flat != nil && len(flat) > 0 { |
|
|
|
for k, v := range flat { |
|
|
|
for k, v := range flat { |
|
|
|
errs[fmt.Sprintf("[%#v].%s.%s", key, se.Struct, k)] = v |
|
|
|
errs[fmt.Sprintf("[%#v].%s.%s", key, se.Struct, k)] = v |
|
|
|
} |
|
|
|
} |
|
|
@ -348,7 +297,10 @@ func (e *StructErrors) Error() string { |
|
|
|
return strings.TrimSpace(buff.String()) |
|
|
|
return strings.TrimSpace(buff.String()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (e *StructErrors) flatten(isFromStruct bool) map[string]*FieldError { |
|
|
|
// Flatten flattens the StructErrors hierarchical structure into a flat namespace style field name
|
|
|
|
|
|
|
|
// for those that want/need it
|
|
|
|
|
|
|
|
func (e *StructErrors) Flatten() map[string]*FieldError { |
|
|
|
|
|
|
|
|
|
|
|
if e == nil { |
|
|
|
if e == nil { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
@ -361,12 +313,6 @@ func (e *StructErrors) flatten(isFromStruct bool) map[string]*FieldError { |
|
|
|
|
|
|
|
|
|
|
|
for k, fe := range flat { |
|
|
|
for k, fe := range flat { |
|
|
|
|
|
|
|
|
|
|
|
// fmt.Println(k)
|
|
|
|
|
|
|
|
// if isFromStruct && k[0:1] == "[" {
|
|
|
|
|
|
|
|
// errs[f.Field+k] = fe
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// errs[k] = fe
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if f.IsPlaceholderErr { |
|
|
|
if f.IsPlaceholderErr { |
|
|
|
errs[f.Field+k] = fe |
|
|
|
errs[f.Field+k] = fe |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -378,7 +324,7 @@ func (e *StructErrors) flatten(isFromStruct bool) map[string]*FieldError { |
|
|
|
|
|
|
|
|
|
|
|
for key, val := range e.StructErrors { |
|
|
|
for key, val := range e.StructErrors { |
|
|
|
|
|
|
|
|
|
|
|
otherErrs := val.flatten(isFromStruct) |
|
|
|
otherErrs := val.Flatten() |
|
|
|
|
|
|
|
|
|
|
|
for _, f2 := range otherErrs { |
|
|
|
for _, f2 := range otherErrs { |
|
|
|
|
|
|
|
|
|
|
@ -390,12 +336,6 @@ func (e *StructErrors) flatten(isFromStruct bool) map[string]*FieldError { |
|
|
|
return errs |
|
|
|
return errs |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Flatten flattens the StructErrors hierarchical structure into a flat namespace style field name
|
|
|
|
|
|
|
|
// for those that want/need it
|
|
|
|
|
|
|
|
func (e *StructErrors) Flatten() map[string]*FieldError { |
|
|
|
|
|
|
|
return e.flatten(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Func accepts all values needed for file and cross field validation
|
|
|
|
// Func accepts all values needed for file and cross field validation
|
|
|
|
// top = top level struct when validating by struct otherwise nil
|
|
|
|
// top = top level struct when validating by struct otherwise nil
|
|
|
|
// current = current level struct when validating by struct otherwise optional comparison value
|
|
|
|
// current = current level struct when validating by struct otherwise optional comparison value
|
|
|
|