/
http.go
64 lines (53 loc) · 1.86 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package http
import (
"github.com/infraboard/mcube/app"
"github.com/infraboard/mcube/http/label"
"github.com/infraboard/mcube/http/router"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"github.com/infraboard/workflow/api/apps/pipeline"
)
var (
api = &handler{}
)
type handler struct {
service pipeline.ServiceServer
log logger.Logger
proxy *Proxy
}
// Registry 注册HTTP服务路由
func (h *handler) Registry(router router.SubRouter) {
r := router.ResourceRouter("pipeline")
r.Permission(true)
r.BasePath("pipelines")
r.Handle("POST", "/", h.CreatePipeline).AddLabel(label.Create)
r.Handle("GET", "/", h.QueryPipeline).AddLabel(label.List)
r.Handle("GET", "/:id", h.DescribePipeline).AddLabel(label.Get)
r.Handle("DELETE", "/:id", h.DeletePipeline).AddLabel(label.Delete)
r.Handle("GET", "/:id/watch_check", h.WatchPipelineCheck).AddLabel(label.Get)
r.BasePath("websocket")
r.Handle("GET", "pipelines/:id/watch", h.WatchPipeline).AddLabel(label.Get)
r.BasePath("steps")
r.Handle("GET", "/", h.QueryStep).AddLabel(label.List)
r.Handle("POST", "/", h.CreateStep).AddLabel(label.Create)
r.Handle("GET", "/:id", h.DescribeStep).AddLabel(label.Get)
r.Handle("DELETE", "/:id", h.DeleteStep).AddLabel(label.Delete)
r.Handle("POST", "/:id/audit", h.AuditStep).AddLabel(label.Update)
r.Handle("POST", "/:id/cancel", h.CancelStep).AddLabel(label.Update)
r.BasePath("variable_templates")
r.Handle("GET", "/", h.QueryVariableTemplate).AddLabel(label.List)
r.BasePath("enums")
r.Handle("GET", "/step_status", h.QueryStepStatusEnum).AddLabel(label.List)
}
func (h *handler) Config() error {
h.service = app.GetGrpcApp(pipeline.AppName).(pipeline.ServiceServer)
h.proxy = NewProxy()
h.log = zap.L().Named("Pipeline")
return nil
}
func (h *handler) Name() string {
return pipeline.AppName
}
func init() {
app.RegistryHttpApp(api)
}