tianxiaoliang commented on a change in pull request #766:
URL: 
https://github.com/apache/servicecomb-service-center/pull/766#discussion_r532385811



##########
File path: server/service/gov/kie/validate.go
##########
@@ -0,0 +1,116 @@
+package kie
+
+import (
+       "fmt"
+)
+
+type Validator struct {
+}
+
+var methodSet map[string]bool
+
+func (d *Validator) Validate(kind string, spec interface{}) error {
+       switch kind {
+       case "match-group":
+               return matchValidate(spec)
+       case "retry":
+               return retryValidate(spec)
+       case "rateLimiting":
+               return rateLimitingValidate(spec)
+       case "circuitBreaker":
+       case "bulkhead":
+       case "loadbalancer":
+               return nil
+       default:
+               return fmt.Errorf("not support kind yet")
+       }
+       return nil
+}
+
+func matchValidate(val interface{}) error {
+       spec, ok := val.(map[string]interface{})
+       if !ok {
+               return fmt.Errorf("illegal item : %v", val)
+       }
+       matches, ok := spec["matches"].([]interface{})
+       if !ok {
+               return fmt.Errorf("illegal item : %v", spec)
+       }
+       for _, match := range matches {
+               match, ok := match.(map[string]interface{})
+               if !ok {
+                       return fmt.Errorf("illegal item : %v", match)
+               }
+               if match["name"] == nil {
+                       return fmt.Errorf("match's name can not be null : %v", 
match)
+               }
+               if match["apiPath"] == nil && match["headers"] == nil && 
match["methods"] == nil {
+                       return fmt.Errorf("match must have a match item 
[apiPath/headers/methods] %v", match)
+               }
+               //apiPath & headers do not check
+               if match["methods"] != nil {
+                       methods, ok := match["methods"].([]string)
+                       if !ok {
+                               return fmt.Errorf("illegal item : %v", match)

Review comment:
       这里有很多地方都要用日志工具去搞,且不能调用以f为结尾的日志工具提供的方法




----------------------------------------------------------------
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:
[email protected]


Reply via email to