summaryrefslogtreecommitdiff
path: root/rpc/service.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 13:10:11 +0300
committerWolfy-J <[email protected]>2018-06-10 13:10:11 +0300
commitd4c007859c002e6af540ec516929de81d03ff82d (patch)
treed7115bded0ae58a08dfe84d8a2cfcdb32c347132 /rpc/service.go
parent2f4e1d950339076574edc50044d6f1ebc3a83a01 (diff)
no immutable services
Diffstat (limited to 'rpc/service.go')
-rw-r--r--rpc/service.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/rpc/service.go b/rpc/service.go
index c07c70b9..268087bc 100644
--- a/rpc/service.go
+++ b/rpc/service.go
@@ -20,19 +20,26 @@ type Service struct {
serving bool
}
-// WithConfig must return Service instance configured with the given environment. Must return error in case of
-// misconfiguration, might return nil as Service if Service is not enabled.
-func (s *Service) WithConfig(cfg service.Config, reg service.Registry) (service.Service, error) {
+// Configure must return configure service and return true if service is enabled. Must return error in case of
+// misconfiguration.
+func (s *Service) Configure(cfg service.Config, reg service.Container) (enabled bool, err error) {
+ if s.cfg != nil {
+ return true, errors.New("service is already configured")
+ }
+
config := &config{}
if err := cfg.Unmarshal(config); err != nil {
- return nil, err
+ return false, err
}
if !config.Enable {
- return nil, nil
+ return false, nil
}
- return &Service{cfg: config, rpc: rpc.NewServer()}, nil
+ s.cfg = config
+ s.rpc = rpc.NewServer()
+
+ return true, nil
}
// Serve serves Service.