summaryrefslogtreecommitdiff
path: root/plugins/rpc
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2020-10-25 12:01:14 +0300
committerWolfy-J <[email protected]>2020-10-25 12:01:14 +0300
commitce661a00ebb29b387ad3dbb17f16324d3882a713 (patch)
treec2987b4aeb25c97d65725d38d5f7bbf0c8945357 /plugins/rpc
parentef0b15ab9eba2bcc5c5b6f147ef7b1351a6679b5 (diff)
- fix excessive config in rpc
Diffstat (limited to 'plugins/rpc')
-rw-r--r--plugins/rpc/rpc.go37
1 files changed, 15 insertions, 22 deletions
diff --git a/plugins/rpc/rpc.go b/plugins/rpc/rpc.go
index 6568eea3..a423da2c 100644
--- a/plugins/rpc/rpc.go
+++ b/plugins/rpc/rpc.go
@@ -9,9 +9,9 @@ import (
"net/rpc"
)
-type PluginRpc interface {
+type RPCService interface {
Name() string
- RpcService() (interface{}, error)
+ RPCService() (interface{}, error)
}
// ID contains default service name.
@@ -24,35 +24,31 @@ type services struct {
// Service is RPC service.
type Service struct {
- // TODO do we need a pointer here since all receivers are pointers??
- rpc *rpc.Server
- configProvider config.Provider
- services []services
- config Config
- close chan struct{}
+ rpc *rpc.Server
+ services []services
+ config Config
+ close chan struct{}
}
// Init rpc service. Must return true if service is enabled.
func (s *Service) Init(cfg config.Provider) error {
- s.configProvider = cfg
- err := s.configProvider.UnmarshalKey(ID, &s.config)
+ err := cfg.UnmarshalKey(ID, &s.config)
if err != nil {
return err
}
- // TODO Do we need to init defaults
- if s.config.Listen == "" {
- s.config.InitDefaults()
- }
-
+ s.config.InitDefaults()
s.close = make(chan struct{})
+ // todo: handle disabled
+
return nil
}
// Serve serves the service.
func (s *Service) Serve() chan error {
errCh := make(chan error, 1)
+
server := rpc.NewServer()
if server == nil {
errCh <- errors.New("rpc server is nil")
@@ -61,6 +57,7 @@ func (s *Service) Serve() chan error {
s.rpc = server
if len(s.services) == 0 {
+ // todo: why this is an error?
errCh <- errors.New("no services with RPC")
return errCh
}
@@ -109,12 +106,12 @@ func (s *Service) Stop() error {
func (s *Service) Depends() []interface{} {
return []interface{}{
- s.RpcService,
+ s.RegisterService,
}
}
-func (s *Service) RpcService(p PluginRpc) error {
- service, err := p.RpcService()
+func (s *Service) RegisterService(p RPCService) error {
+ service, err := p.RPCService()
if err != nil {
return err
}
@@ -144,10 +141,6 @@ func (s *Service) Register(name string, svc interface{}) error {
// Client creates new RPC client.
func (s *Service) Client() (*rpc.Client, error) {
- if s.configProvider == nil {
- return nil, errors.New("RPC service is not configured")
- }
-
conn, err := s.config.Dialer()
if err != nil {
return nil, err