Merge pull request #822 from micro/service

Add Name to Service
This commit is contained in:
Asim Aslam 2019-10-07 08:43:07 +01:00 committed by GitHub
commit fa6590f999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -14,11 +14,19 @@ type serviceKey struct{}
// within go-micro. Its a convenience method for building // within go-micro. Its a convenience method for building
// and initialising services. // and initialising services.
type Service interface { type Service interface {
// The service name
Name() string
// Init initialises options
Init(...Option) Init(...Option)
// Options returns the current options
Options() Options Options() Options
// Client is used to call services
Client() client.Client Client() client.Client
// Server is for handling requests and events
Server() server.Server Server() server.Server
// Run the service
Run() error Run() error
// The service implementation
String() string String() string
} }

View File

@ -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 // Init initialises options. Additionally it calls cmd.Init
// which parses command line flags. cmd.Init is only called // which parses command line flags. cmd.Init is only called
// on first Init. // on first Init.

View File

@ -6,11 +6,20 @@ import (
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
) )
// Service is an interface for a micro service
type Service interface { type Service interface {
// The service name
Name() string
// Init initialises options
Init(...Option) Init(...Option)
// Options returns the current options
Options() Options Options() Options
// Client is used to call services
Client() client.Client Client() client.Client
// Server is for handling requests and events
Server() server.Server Server() server.Server
// Run the service
Run() error Run() error
// The service implementation
String() string String() string
} }