update error(err) to err (#1416)

the pull request update `return error(err)` to `return err`, and remove `kindOfData`.
This commit is contained in:
田欧 2018-07-01 21:10:48 +08:00 committed by Bo-Yi Wu
parent eb9f313144
commit cdd02fa9d6
2 changed files with 10 additions and 14 deletions

View File

@ -4,10 +4,9 @@
package binding package binding
import ( import "net/http"
"net/http"
)
// Content-Type MIME of the most common data formats.
const ( const (
MIMEJSON = "application/json" MIMEJSON = "application/json"
MIMEHTML = "text/html" MIMEHTML = "text/html"

View File

@ -18,11 +18,17 @@ type defaultValidator struct {
var _ StructValidator = &defaultValidator{} var _ StructValidator = &defaultValidator{}
// ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.
func (v *defaultValidator) ValidateStruct(obj interface{}) error { func (v *defaultValidator) ValidateStruct(obj interface{}) error {
if kindOfData(obj) == reflect.Struct { value := reflect.ValueOf(obj)
valueType := value.Kind()
if valueType == reflect.Ptr {
valueType = value.Elem().Kind()
}
if valueType == reflect.Struct {
v.lazyinit() v.lazyinit()
if err := v.validate.Struct(obj); err != nil { if err := v.validate.Struct(obj); err != nil {
return error(err) return err
} }
} }
return nil return nil
@ -43,12 +49,3 @@ func (v *defaultValidator) lazyinit() {
v.validate = validator.New(config) v.validate = validator.New(config)
}) })
} }
func kindOfData(data interface{}) reflect.Kind {
value := reflect.ValueOf(data)
valueType := value.Kind()
if valueType == reflect.Ptr {
valueType = value.Elem().Kind()
}
return valueType
}