From 7b6749c9be47827d125439d71e373ca7168f0eee Mon Sep 17 00:00:00 2001 From: novikovmu Date: Thu, 15 Sep 2022 10:58:31 +0300 Subject: [PATCH] MSP-1021 init routes --- routes/routes.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 routes/routes.go diff --git a/routes/routes.go b/routes/routes.go new file mode 100644 index 0000000..c2cd8e7 --- /dev/null +++ b/routes/routes.go @@ -0,0 +1,54 @@ +package routes + +import ( + "github.com/integration-system/isp-kit/cluster" + "github.com/integration-system/isp-kit/grpc" + "github.com/integration-system/isp-kit/grpc/endpoint" + "github.com/integration-system/isp-kit/grpc/isp" + "isp-script-service/controller" +) + +type Controllers struct { + Script controller.Script +} + +func EndpointDescriptors() []cluster.EndpointDescriptor { + return endpointDescriptors(Controllers{}) +} + +func Handler(wrapper endpoint.Wrapper, c Controllers) isp.BackendServiceServer { + muxer := grpc.NewMux() + for _, descriptor := range endpointDescriptors(c) { + muxer.Handle(descriptor.Path, wrapper.Endpoint(descriptor.Handler)) + } + return muxer +} + +func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor { + return []cluster.EndpointDescriptor{ + { + Path: "script/execute", + Inner: true, + UserAuthRequired: false, + Handler: c.Script.Execute, + }, + { + Path: "script/batch_execute", + Inner: true, + UserAuthRequired: false, + Handler: c.Script.BatchExecute, + }, + { + Path: "script/execute_by_id", + Inner: true, + UserAuthRequired: false, + Handler: c.Script.ExecuteById, + }, + { + Path: "script/batch_execute_by_ids", + Inner: true, + UserAuthRequired: false, + Handler: c.Script.BatchExecuteById, + }, + } +}