Skip to content

Commit

Permalink
优化binding功能
Browse files Browse the repository at this point in the history
  • Loading branch information
karldoenitz committed Mar 29, 2019
1 parent 2770359 commit f502289
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion binding/validate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package binding

import (
"errors"
"fmt"
"github.com/karldoenitz/Tigo/logger"
"reflect"
Expand Down Expand Up @@ -80,7 +81,19 @@ func checkMapField(field reflect.StructField, vField reflect.Value) error {

// checkSliceField 对切片类型的字段进行校验
func checkSliceField(field reflect.StructField, vField reflect.Value) error {
logger.Warning.Printf("Do not support slice kind field: %s value: %s", field.Name, vField.String())
for i := 0; i < vField.Len(); i++ {
v := vField.Index(i)
t := v.Type()
if v.Kind() == reflect.Struct || v.Kind() == reflect.Interface {
err := checkObjBinding(t, v)
if err != nil {
return errors.New(fmt.Sprintf("Field %s=>index %d has an error: %s", field.Name, i, err.Error()))
}
} else {
logger.Warning.Printf("Only support interface/struct kind field: %s", field.Name)
break
}
}
return nil
}

Expand Down

0 comments on commit f502289

Please sign in to comment.