From 85ae2329368a519f17746e7134a8d7eb4e02c75a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Jul 2020 21:15:59 +0100 Subject: [PATCH] Add model to service (#1819) --- service/grpc/grpc.go | 5 +++++ service/mucp/mucp.go | 5 +++++ service/options.go | 10 ++++++++++ service/service.go | 3 +++ 4 files changed, 23 insertions(+) diff --git a/service/grpc/grpc.go b/service/grpc/grpc.go index e5d46bb5..1ab6cb23 100644 --- a/service/grpc/grpc.go +++ b/service/grpc/grpc.go @@ -3,6 +3,7 @@ package grpc import ( "github.com/micro/go-micro/v2/client" gclient "github.com/micro/go-micro/v2/client/grpc" + "github.com/micro/go-micro/v2/model" "github.com/micro/go-micro/v2/server" gserver "github.com/micro/go-micro/v2/server/grpc" "github.com/micro/go-micro/v2/service" @@ -46,6 +47,10 @@ func (s *grpcService) Server() server.Server { return s.opts.Server } +func (s *grpcService) Model() model.Model { + return s.opts.Model +} + func (s *grpcService) String() string { return "grpc" } diff --git a/service/mucp/mucp.go b/service/mucp/mucp.go index d8238014..b8854cfd 100644 --- a/service/mucp/mucp.go +++ b/service/mucp/mucp.go @@ -4,6 +4,7 @@ package mucp import ( "github.com/micro/go-micro/v2/client" cmucp "github.com/micro/go-micro/v2/client/mucp" + "github.com/micro/go-micro/v2/model" "github.com/micro/go-micro/v2/server" smucp "github.com/micro/go-micro/v2/server/mucp" "github.com/micro/go-micro/v2/service" @@ -47,6 +48,10 @@ func (s *mucpService) Server() server.Server { return s.opts.Server } +func (s *mucpService) Model() model.Model { + return s.opts.Model +} + func (s *mucpService) String() string { return "mucp" } diff --git a/service/options.go b/service/options.go index af26fc52..424c5746 100644 --- a/service/options.go +++ b/service/options.go @@ -6,6 +6,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/model" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/transport" @@ -15,6 +16,7 @@ type Options struct { Broker broker.Broker Client client.Client Server server.Server + Model model.Model Registry registry.Registry Transport transport.Transport @@ -72,12 +74,20 @@ func Context(ctx context.Context) Option { } } +// Server sets the server for handling requests func Server(s server.Server) Option { return func(o *Options) { o.Server = s } } +// Model sets the model for data access +func Model(m model.Model) Option { + return func(o *Options) { + o.Model = m + } +} + // Registry sets the registry for the service // and the underlying components func Registry(r registry.Registry) Option { diff --git a/service/service.go b/service/service.go index 31d943b8..67430316 100644 --- a/service/service.go +++ b/service/service.go @@ -3,6 +3,7 @@ package service import ( "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/model" "github.com/micro/go-micro/v2/server" ) @@ -18,6 +19,8 @@ type Service interface { Client() client.Client // Server is for handling requests and events Server() server.Server + // Model is used to access data + Model() model.Model // Run the service Run() error // The service implementation