Add model to service (#1819)
This commit is contained in:
parent
13ea0eec02
commit
85ae232936
@ -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"
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user