remove the double isStruct/isStructPtr check
Showing
1 changed file
with
2 additions
and
2 deletions
| ... | @@ -342,6 +342,7 @@ func (v *Validation) Valid(obj interface{}) (b bool, err error) { | ... | @@ -342,6 +342,7 @@ func (v *Validation) Valid(obj interface{}) (b bool, err error) { |
| 342 | // Anonymous fields will be ignored | 342 | // Anonymous fields will be ignored |
| 343 | func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { | 343 | func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { |
| 344 | //Step 1: validate obj itself firstly | 344 | //Step 1: validate obj itself firstly |
| 345 | // fails if objc is not struct | ||
| 345 | pass, err := v.Valid(objc) | 346 | pass, err := v.Valid(objc) |
| 346 | if err != nil || false == pass { | 347 | if err != nil || false == pass { |
| 347 | return pass, err // Stop recursive validation | 348 | return pass, err // Stop recursive validation |
| ... | @@ -349,7 +350,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { | ... | @@ -349,7 +350,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { |
| 349 | // Step 2: Validate struct's struct fields | 350 | // Step 2: Validate struct's struct fields |
| 350 | objT := reflect.TypeOf(objc) | 351 | objT := reflect.TypeOf(objc) |
| 351 | objV := reflect.ValueOf(objc) | 352 | objV := reflect.ValueOf(objc) |
| 352 | if isStruct(objT) || isStructPtr(objT) { | ||
| 353 | 353 | ||
| 354 | if isStructPtr(objT) { | 354 | if isStructPtr(objT) { |
| 355 | objT = objT.Elem() | 355 | objT = objT.Elem() |
| ... | @@ -360,6 +360,7 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { | ... | @@ -360,6 +360,7 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { |
| 360 | 360 | ||
| 361 | t := objT.Field(i).Type | 361 | t := objT.Field(i).Type |
| 362 | 362 | ||
| 363 | // Recursive applies to struct or pointer to structs fields | ||
| 363 | if isStruct(t) || isStructPtr(t) { | 364 | if isStruct(t) || isStructPtr(t) { |
| 364 | // Step 3: do the recursive validation | 365 | // Step 3: do the recursive validation |
| 365 | // Only valid the Public field recursively | 366 | // Only valid the Public field recursively |
| ... | @@ -368,7 +369,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { | ... | @@ -368,7 +369,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { |
| 368 | } | 369 | } |
| 369 | } | 370 | } |
| 370 | } | 371 | } |
| 371 | } | ||
| 372 | 372 | ||
| 373 | return pass, err | 373 | return pass, err |
| 374 | } | 374 | } | ... | ... |
-
Please register or sign in to post a comment