tianxiaoliang commented on a change in pull request #787: URL: https://github.com/apache/servicecomb-service-center/pull/787#discussion_r550090218
########## File path: server/service/gov/mock/mock.go ########## @@ -32,36 +34,87 @@ type Distributor struct { name string } -func (d *Distributor) Create(kind, project string, spec []byte) error { +const MatchGroup = "match-group" + +var PolicyNames = []string{"retry", "rateLimiting", "circuitBreaker", "bulkhead"} + +func (d *Distributor) Create(kind, project string, spec []byte) ([]byte, error) { p := &gov.Policy{} err := json.Unmarshal(spec, p) + p.ID = uuid.NewV4().String() + p.Kind = kind log.Println(fmt.Sprintf("create %v", &p)) - d.lbPolicies[p.GovernancePolicy.Name] = p - return err + d.lbPolicies[p.GovernancePolicy.ID] = p + return []byte(p.ID), err } + func (d *Distributor) Update(id, kind, project string, spec []byte) error { + if d.lbPolicies[id] == nil { + return fmt.Errorf("id not exsit") + } p := &gov.Policy{} err := json.Unmarshal(spec, p) + p.ID = id + p.Kind = kind log.Println("update ", p) - d.lbPolicies[p.GovernancePolicy.Name] = p + d.lbPolicies[p.GovernancePolicy.ID] = p return err } + func (d *Distributor) Delete(id, project string) error { delete(d.lbPolicies, id) return nil } + +func (d *Distributor) Display(project, app, env string) ([]byte, error) { + list := make([]*gov.Policy, 0) + for _, g := range d.lbPolicies { + if g.Kind == MatchGroup && g.Selector.App == app && g.Selector.Environment == env { + list = append(list, g) + } + } + policyMap := make(map[string]*gov.Policy) + for _, g := range d.lbPolicies { + for _, kind := range PolicyNames { + if g.Kind == kind && g.Selector.App == app && g.Selector.Environment == env { Review comment: 79 72 可以抽取 ---------------------------------------------------------------- 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