You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "Wanghb1 (via GitHub)" <gi...@apache.org> on 2025/08/29 03:20:52 UTC
Re: [PR] support custom validator,add weak password validator [servicecomb-service-center]
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: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org