diff --git a/pkg/extension/server.go b/pkg/extension/server.go index 4f8f3baef6ceeaa624aeb74ebaaffb805ac511cd..42c1f241e93bca687c5cf0afd75d63a74ceb22f2 100644 --- a/pkg/extension/server.go +++ b/pkg/extension/server.go @@ -7,7 +7,9 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/action" "git.perx.ru/perxis/perxis-go/pkg/errors" "git.perx.ru/perxis/perxis-go/pkg/operation" + commonpb "git.perx.ru/perxis/perxis-go/proto/common" pb "git.perx.ru/perxis/perxis-go/proto/extensions" + "google.golang.org/grpc" "google.golang.org/protobuf/proto" ) @@ -21,8 +23,7 @@ func DefaultWrapErrFn() WrapErrFn { type ServerOption func(c *Server) -// WrapErrs Оборачивать ошибки, возвращаемые от каждого из -// расширений, в название расширения +// WrapErrs Оборачивать ошибки, возвращаемые от каждого из расширений, в название расширения func WrapErrs() ServerOption { return func(c *Server) { c.wrapErr = func(extension Extension, err error) error { @@ -80,10 +81,9 @@ type Server struct { pb.UnimplementedExtensionServiceServer } -func NewServer(operation operation.Service, options ...ServerOption) *Server { +func NewServer(options ...ServerOption) *Server { srv := &Server{ - // todo: нужно как-то неявно создавать и регистрировать сервер операций - ? - operations: operation, + operations: operation.NewDefaultService(), wrapErr: DefaultWrapErrFn(), } @@ -94,6 +94,11 @@ func NewServer(operation operation.Service, options ...ServerOption) *Server { return srv } +func RegisterServer(grpcSrv *grpc.Server, srv *Server) { + commonpb.RegisterOperationServiceServer(grpcSrv, operation.NewServer(srv.operations)) + pb.RegisterExtensionServiceServer(grpcSrv, srv) +} + func (s *Server) Install(ctx context.Context, req *InstallRequest) (*operation.Proto, error) { exts, err := s.extensions(ctx, req.Extensions...) if err != nil { diff --git a/pkg/extension/server_test.go b/pkg/extension/server_test.go index cb6d6d3aad1521fc316e766cf8719cb4981121a3..f80988fab0c7846ed79bcf340cbd22a0748b13c5 100644 --- a/pkg/extension/server_test.go +++ b/pkg/extension/server_test.go @@ -7,7 +7,6 @@ import ( "testing" "git.perx.ru/perxis/perxis-go/pkg/errors" - "git.perx.ru/perxis/perxis-go/pkg/operation" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -119,7 +118,7 @@ func TestServer_Action(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - srv := NewServer(operation.NewDefaultService(), NamedExtensions(tt.extension)) + srv := NewServer(NamedExtensions(tt.extension)) got, err := srv.Action(context.Background(), tt.in) if tt.wantErr != "" { require.Error(t, err)