From b59454740852128b7e0b23591f8774e581ff921f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 7 Oct 2019 08:32:28 +0100 Subject: [PATCH 1/2] Add service Name --- micro.go | 8 ++++++++ service.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/micro.go b/micro.go index 44bc52fc..295c08c5 100644 --- a/micro.go +++ b/micro.go @@ -14,11 +14,19 @@ type serviceKey struct{} // within go-micro. Its a convenience method for building // and initialising services. type Service interface { + // The service name + Name() string + // Init initialises options Init(...Option) + // Options returns the current options Options() Options + // Client is used to call services Client() client.Client + // Server is for handling requests and events Server() server.Server + // Run the service Run() error + // The service implementation String() string } diff --git a/service.go b/service.go index eed7f8ac..a0f9817c 100644 --- a/service.go +++ b/service.go @@ -37,6 +37,10 @@ func newService(opts ...Option) Service { } } +func (s *service) Name() string { + return s.opts.Server.Options().Name +} + // Init initialises options. Additionally it calls cmd.Init // which parses command line flags. cmd.Init is only called // on first Init. From fd8a0fb2f5141c1458637f308b529198619241b6 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 7 Oct 2019 08:34:15 +0100 Subject: [PATCH 2/2] Update internal service definition --- service/service.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/service/service.go b/service/service.go index 5b9d3027..aca8acd6 100644 --- a/service/service.go +++ b/service/service.go @@ -6,11 +6,20 @@ import ( "github.com/micro/go-micro/server" ) +// Service is an interface for a micro service type Service interface { + // The service name + Name() string + // Init initialises options Init(...Option) + // Options returns the current options Options() Options + // Client is used to call services Client() client.Client + // Server is for handling requests and events Server() server.Server + // Run the service Run() error + // The service implementation String() string }