From abced1b1593bdd3abfafb2264a2ac9d2d1f6e69d Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Thu, 26 Mar 2020 07:55:35 +0000 Subject: [PATCH] [Roll] interface name changing --- binding/binding.go | 12 ++++++------ binding/default_validator.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/binding/binding.go b/binding/binding.go index dce95e81..9c6cc27f 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -45,27 +45,27 @@ type BindingUri interface { BindUri(map[string][]string, interface{}) error } -// Validater is the minimal interface which needs to be implemented in +// StructValidator is the minimal interface which needs to be implemented in // order for it to be used as the validator engine for ensuring the correctness // of the request. Gin provides a default implementation for this using // https://github.com/go-playground/validator/tree/v8.18.2. -type Validater interface { +type StructValidator interface { // If the received type is a slice|array, the validation should be performed travel on every element. // If the received type is not a struct or slice|array, any validation should be skipped and nil must be returned. // If the received type is a struct or pointer to a struct, the validation should be performed. // If the struct is not valid or the validation itself fails, a descriptive error should be returned. // Otherwise nil must be returned. - Validate(interface{}) error + ValidateStruct(interface{}) error // Engine returns the underlying validator engine which powers the - // StructValidator implementation. + // Validater implementation. Engine() interface{} } // Validator is the default validator which implements the StructValidator // interface. It uses https://github.com/go-playground/validator/tree/v8.18.2 // under the hood. -var Validator Validater = &defaultValidator{} +var Validator StructValidator = &defaultValidator{} // These implement the Binding interface and can be used to bind the data // present in the request to struct instances. @@ -112,5 +112,5 @@ func validate(obj interface{}) error { if Validator == nil { return nil } - return Validator.Validate(obj) + return Validator.ValidateStruct(obj) } diff --git a/binding/default_validator.go b/binding/default_validator.go index 9c44eefe..eed2f06d 100644 --- a/binding/default_validator.go +++ b/binding/default_validator.go @@ -31,10 +31,10 @@ func (err sliceValidateError) Error() string { return strings.Join(errMsgs, "\n") } -var _ Validater = &defaultValidator{} +var _ StructValidator = &defaultValidator{} // ValidateStruct receives any kind of type, but only performed struct or pointer to struct type. -func (v *defaultValidator) Validate(obj interface{}) error { +func (v *defaultValidator) ValidateStruct(obj interface{}) error { if obj == nil { return nil } @@ -42,7 +42,7 @@ func (v *defaultValidator) Validate(obj interface{}) error { value := reflect.ValueOf(obj) valueType := value.Kind() if valueType == reflect.Ptr { - return v.Validate(value.Elem().Interface()) + return v.ValidateStruct(value.Elem().Interface()) } switch valueType { @@ -52,7 +52,7 @@ func (v *defaultValidator) Validate(obj interface{}) error { count := value.Len() validateRet := make(sliceValidateError, 0) for i := 0; i < count; i++ { - if err := v.Validate(value.Index(i).Interface()); err != nil { + if err := v.ValidateStruct(value.Index(i).Interface()); err != nil { validateRet = append(validateRet, err) } }