73650e1f by Wyatt Fang

remove the double isStruct/isStructPtr check

1 parent d0e7dd68
...@@ -341,6 +341,7 @@ func (v *Validation) Valid(obj interface{}) (b bool, err error) { ...@@ -341,6 +341,7 @@ func (v *Validation) Valid(obj interface{}) (b bool, err error) {
341 // Anonymous fields will be ignored 341 // Anonymous fields will be ignored
342 func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { 342 func (v *Validation) RecursiveValid(objc interface{}) (bool, error) {
343 //Step 1: validate obj itself firstly 343 //Step 1: validate obj itself firstly
344 // fails if objc is not struct
344 pass, err := v.Valid(objc) 345 pass, err := v.Valid(objc)
345 if err != nil || false == pass { 346 if err != nil || false == pass {
346 return pass, err // Stop recursive validation 347 return pass, err // Stop recursive validation
...@@ -348,7 +349,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { ...@@ -348,7 +349,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) {
348 // Step 2: Validate struct's struct fields 349 // Step 2: Validate struct's struct fields
349 objT := reflect.TypeOf(objc) 350 objT := reflect.TypeOf(objc)
350 objV := reflect.ValueOf(objc) 351 objV := reflect.ValueOf(objc)
351 if isStruct(objT) || isStructPtr(objT) {
352 352
353 if isStructPtr(objT) { 353 if isStructPtr(objT) {
354 objT = objT.Elem() 354 objT = objT.Elem()
...@@ -359,6 +359,7 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { ...@@ -359,6 +359,7 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) {
359 359
360 t := objT.Field(i).Type 360 t := objT.Field(i).Type
361 361
362 // Recursive applies to struct or pointer to structs fields
362 if isStruct(t) || isStructPtr(t) { 363 if isStruct(t) || isStructPtr(t) {
363 // Step 3: do the recursive validation 364 // Step 3: do the recursive validation
364 // Only valid the Public field recursively 365 // Only valid the Public field recursively
...@@ -367,7 +368,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) { ...@@ -367,7 +368,6 @@ func (v *Validation) RecursiveValid(objc interface{}) (bool, error) {
367 } 368 }
368 } 369 }
369 } 370 }
370 }
371 371
372 return pass, err 372 return pass, err
373 } 373 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!