diff options
Diffstat (limited to 'service/rpc')
-rw-r--r-- | service/rpc/service.go | 17 | ||||
-rw-r--r-- | service/rpc/service_test.go | 10 |
2 files changed, 19 insertions, 8 deletions
diff --git a/service/rpc/service.go b/service/rpc/service.go index 6e231048..3ea6c5fc 100644 --- a/service/rpc/service.go +++ b/service/rpc/service.go @@ -3,12 +3,19 @@ package rpc import ( "errors" "github.com/spiral/goridge" + "github.com/spiral/roadrunner/service/env" "net/rpc" "sync" ) -// ID contains default service name. -const ID = "rpc" +const ( + // ID contains default service name. + ID = "rpc" + + // rrKey defines environment key to be used to store information about + // rpc server connection. + envKey = "rr_rpc" +) // Service is RPC service. type Service struct { @@ -20,7 +27,7 @@ type Service struct { } // Init rpc service. Must return true if service is enabled. -func (s *Service) Init(cfg *Config) (bool, error) { +func (s *Service) Init(cfg *Config, env env.Environment) (bool, error) { if !cfg.Enable { return false, nil } @@ -28,6 +35,10 @@ func (s *Service) Init(cfg *Config) (bool, error) { s.cfg = cfg s.rpc = rpc.NewServer() + if env != nil { + env.SetEnv(envKey, cfg.Listen) + } + return true, nil } diff --git a/service/rpc/service_test.go b/service/rpc/service_test.go index fc88d38d..59e0e05d 100644 --- a/service/rpc/service_test.go +++ b/service/rpc/service_test.go @@ -12,7 +12,7 @@ func (ts *testService) Echo(msg string, r *string) error { *r = msg; return nil func Test_Disabled(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: false}) + ok, err := s.Init(&Config{Enable: false}, nil) assert.NoError(t, err) assert.False(t, ok) @@ -30,7 +30,7 @@ func Test_RegisterNotConfigured(t *testing.T) { func Test_Enabled(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}, nil) assert.NoError(t, err) assert.True(t, ok) @@ -38,7 +38,7 @@ func Test_Enabled(t *testing.T) { func Test_StopNonServing(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9008"}, nil) assert.NoError(t, err) assert.True(t, ok) @@ -47,7 +47,7 @@ func Test_StopNonServing(t *testing.T) { func Test_Serve_Errors(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "mailformed"}) + ok, err := s.Init(&Config{Enable: true, Listen: "mailformed"}, nil) assert.NoError(t, err) assert.True(t, ok) @@ -60,7 +60,7 @@ func Test_Serve_Errors(t *testing.T) { func Test_Serve_Client(t *testing.T) { s := &Service{} - ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9018"}) + ok, err := s.Init(&Config{Enable: true, Listen: "tcp://localhost:9018"}, nil) assert.NoError(t, err) assert.True(t, ok) |