Add model to service (#1819)

This commit is contained in:
Asim Aslam 2020-07-11 21:15:59 +01:00 committed by GitHub
parent 13ea0eec02
commit 85ae232936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package grpc
import ( import (
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
gclient "github.com/micro/go-micro/v2/client/grpc" gclient "github.com/micro/go-micro/v2/client/grpc"
"github.com/micro/go-micro/v2/model"
"github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/server"
gserver "github.com/micro/go-micro/v2/server/grpc" gserver "github.com/micro/go-micro/v2/server/grpc"
"github.com/micro/go-micro/v2/service" "github.com/micro/go-micro/v2/service"
@ -46,6 +47,10 @@ func (s *grpcService) Server() server.Server {
return s.opts.Server return s.opts.Server
} }
func (s *grpcService) Model() model.Model {
return s.opts.Model
}
func (s *grpcService) String() string { func (s *grpcService) String() string {
return "grpc" return "grpc"
} }

View File

@ -4,6 +4,7 @@ package mucp
import ( import (
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
cmucp "github.com/micro/go-micro/v2/client/mucp" cmucp "github.com/micro/go-micro/v2/client/mucp"
"github.com/micro/go-micro/v2/model"
"github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/server"
smucp "github.com/micro/go-micro/v2/server/mucp" smucp "github.com/micro/go-micro/v2/server/mucp"
"github.com/micro/go-micro/v2/service" "github.com/micro/go-micro/v2/service"
@ -47,6 +48,10 @@ func (s *mucpService) Server() server.Server {
return s.opts.Server return s.opts.Server
} }
func (s *mucpService) Model() model.Model {
return s.opts.Model
}
func (s *mucpService) String() string { func (s *mucpService) String() string {
return "mucp" return "mucp"
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/broker"
"github.com/micro/go-micro/v2/client" "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/registry"
"github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v2/transport" "github.com/micro/go-micro/v2/transport"
@ -15,6 +16,7 @@ type Options struct {
Broker broker.Broker Broker broker.Broker
Client client.Client Client client.Client
Server server.Server Server server.Server
Model model.Model
Registry registry.Registry Registry registry.Registry
Transport transport.Transport 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 { func Server(s server.Server) Option {
return func(o *Options) { return func(o *Options) {
o.Server = s 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 // Registry sets the registry for the service
// and the underlying components // and the underlying components
func Registry(r registry.Registry) Option { func Registry(r registry.Registry) Option {

View File

@ -3,6 +3,7 @@ package service
import ( import (
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/model"
"github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/server"
) )
@ -18,6 +19,8 @@ type Service interface {
Client() client.Client Client() client.Client
// Server is for handling requests and events // Server is for handling requests and events
Server() server.Server Server() server.Server
// Model is used to access data
Model() model.Model
// Run the service // Run the service
Run() error Run() error
// The service implementation // The service implementation