diff --git a/options/options.go b/options/options.go index 5e08541..44cfda5 100644 --- a/options/options.go +++ b/options/options.go @@ -11,14 +11,15 @@ import ( // Options holds the configuration for a service instance type Options struct { - Name string - ListenAddr string - Logger logger.Logger - Codec codec.Codec - Transport transport.Transport - Router router.Router - Broker broker.Broker - Config config.Config + Name string + RPCPort int16 + + Logger logger.Logger + Codec codec.Codec + Transport transport.Transport + Router router.Router + Broker broker.Broker + Config config.Config } // Option represents a function that can be used to mutate an Options object @@ -31,10 +32,10 @@ func Name(name string) Option { } } -// ListenAddr sets the address in which the gRPC server will listen on -func ListenAddr(addr string) Option { +// RPCPort sets the port in which this service's RPC will listen on, as well as the port in which other services' RPC servers are listening on +func RPCPort(port int16) Option { return func(o *Options) { - o.ListenAddr = addr + o.RPCPort = port } } diff --git a/server/server.go b/server/server.go index 3583aca..e510ffa 100644 --- a/server/server.go +++ b/server/server.go @@ -33,7 +33,7 @@ func NewServer(opts *options.Options) Server { func (s *server) Start() error { ctx := context.Background() - l, err := s.opts.Transport.Listen(ctx, s.opts.ListenAddr) + l, err := s.opts.Transport.Listen(ctx, fmt.Sprintf(":%d", s.opts.RPCPort)) if err != nil { return err } diff --git a/service.go b/service.go index f10bdf6..77330f3 100644 --- a/service.go +++ b/service.go @@ -36,6 +36,7 @@ type service struct { func NewService(opts ...options.Option) Service { svc := &service{} svc.options.Logger = logger.NewStdoutLogger() + svc.options.RPCPort = 7070 svc.Apply(opts...) @@ -73,9 +74,6 @@ func (s *service) Start() error { if s.options.Name == "" { return errors.New("missing service name") } - if s.options.ListenAddr == "" { - return errors.New("missing listen address") - } if s.options.Broker != nil { if err := s.options.Broker.Connect(context.Background()); err != nil {