MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / online

Method online

gateway/apinto/project.go:54–118  ·  view source on GitHub ↗
(ctx context.Context, project *gateway.ProjectRelease)

Source from the content-addressed store, hash-verified

52}
53
54func (p *ProjectClient) online(ctx context.Context, project *gateway.ProjectRelease) error {
55 if project == nil {
56 return nil
57 }
58 matches := map[string]string{
59 "project": project.Id,
60 }
61 if project.Upstream != nil {
62 upstreamId := genWorkerID(project.Upstream.ID, gateway.ProfessionService)
63 err := p.client.Set(ctx, upstreamId, entity.ToService(project.Upstream, project.Version, matches))
64 if err != nil {
65 return err
66 }
67 }
68
69 routers, err := matchLabels[entity.Router](ctx, p.client, gateway.ProfessionRouter, matches)
70 if err != nil {
71 if !errors.Is(err, proto.Nil) {
72 return err
73 }
74 }
75 routerMap := utils.SliceToMap(routers, func(t *entity.Router) string {
76 return t.ID
77 })
78
79 for _, api := range project.Apis {
80 id := genWorkerID(api.ID, gateway.ProfessionRouter)
81 if api.Labels == nil {
82 api.Labels = make(map[string]string)
83 }
84 api.Labels["provider"] = project.Id
85 routerInfo := entity.ToRouter(api, project.Version, matches)
86
87 err = driver.ApiPublish(ctx, p.client, routerInfo, api.Extends)
88 if err != nil {
89 return err
90 }
91 delete(routerMap, id)
92 }
93 // 发布策略
94 for _, s := range project.Strategies {
95 if s.Config.IsDelete {
96 p.client.Del(ctx, genWorkerID(s.Config.Name, gateway.ProfessionStrategy))
97 continue
98 }
99 err := p.client.Set(ctx, genWorkerID(s.Config.Name, gateway.ProfessionStrategy), s)
100 if err != nil {
101 return err
102 }
103 }
104 // 删除多余配置
105 for _, v := range routerMap {
106 err := driver.ApiDelete(ctx, p.client, v)
107 if err != nil {
108 return err
109 }
110 err = p.client.Del(ctx, v.ID)
111 if err != nil {

Callers 3

OnlineMethod · 0.95
SystemInsidePublicListFunction · 0.45

Calls 8

ToServiceFunction · 0.92
ToRouterFunction · 0.92
ApiPublishFunction · 0.92
ApiDeleteFunction · 0.92
genWorkerIDFunction · 0.85
matchLabelsFunction · 0.85
SetMethod · 0.65
DelMethod · 0.45

Tested by

no test coverage detected