Wanghb1 commented on code in PR #1519:
URL: 
https://github.com/apache/servicecomb-service-center/pull/1519#discussion_r2309028234


##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
        }
        return nil
 }
+
+func customValidate(v interface{}, targetValidators ...string) error {
+       if len(customValidators) == 0 {
+               return nil
+       }
+       for _, validatorName := range targetValidators {
+               validator, exists := customValidators[validatorName]
+               if !exists {
+                       log.Info(fmt.Sprintf("validator:%s is not 
registered,skip", validatorName))
+                       continue
+               }
+               validate, err := validator.Validate(v)
+               if err != nil {
+                       return err
+               }
+               if !validate {
+                       return errors.New(fmt.Sprintf("Validate 
failed,validator:%s", validatorName))

Review Comment:
   建议多个err一起输出



##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
        }
        return nil
 }
+
+func customValidate(v interface{}, targetValidators ...string) error {
+       if len(customValidators) == 0 {
+               return nil
+       }
+       for _, validatorName := range targetValidators {
+               validator, exists := customValidators[validatorName]
+               if !exists {
+                       log.Info(fmt.Sprintf("validator:%s is not 
registered,skip", validatorName))
+                       continue
+               }
+               validate, err := validator.Validate(v)
+               if err != nil {
+                       return err
+               }
+               if !validate {
+                       return errors.New(fmt.Sprintf("Validate 
failed,validator:%s", validatorName))
+               }
+               return nil
+       }
+       return nil
+}
+
+func initCustomValidator() {

Review Comment:
   initCustomValidator和passwordValidator 放在validate_rbac.go里面



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to