tianxiaoliang commented on a change in pull request #124: Support parameter 
validation
URL: https://github.com/apache/servicecomb-kie/pull/124#discussion_r397672904
 
 

 ##########
 File path: pkg/validate/instance.go
 ##########
 @@ -0,0 +1,37 @@
+package validate
+
+import "github.com/go-mesh/openlogging"
+
+var defaultValidator *Validator
+
+// custom validate rules
+// tag names suggested to be "kie*", to distinguish from third party tags
+var customRules = []*RegexValidateRule{
+       NewRule("kieKey", 
`^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$`, &Option{Min: 1, Max: 
256}),
+       NewRule("kieValueType", `^(string|ini|json|text|yaml|properties)$`, 
nil),
+       NewRule("kieKvStatus", `^(enabled|disabled){0,1}$`, nil),
+}
+
+// tags of third party validate rules we used, for error translation
+var thirdPartyTags = []string{
+       "min", "max", "length",
+}
+
+func init() {
+       defaultValidator = NewValidator()
+       for _, r := range customRules {
+               if err := defaultValidator.RegisterRule(r); err != nil {
+                       openlogging.Fatal("Init validate failed: " + 
err.Error())
 
 Review comment:
   init中不建议panic,显示的调用Init方法吧,初始化失败就推出,运行时突然因为第一次初始化validate而导致panic,这不合理

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to