Documentation ¶
Overview ¶
Package service implements the base structure of a platform application.
Index ¶
- Constants
- type RunFunc
- type Service
- func (s *Service) Config() *config.Config
- func (s *Service) Creds() *credentials.Store
- func (s *Service) Discovery() *discovery.Service
- func (s *Service) Error(err error)
- func (s *Service) Exit(status int)
- func (s *Service) ID() string
- func (s *Service) IsLeader() bool
- func (s *Service) LoadCredentials(creds ...credentials.Credential)
- func (s *Service) LoadDiscoveryConfig()
- func (s *Service) LoadGrpcClientConfig()
- func (s *Service) LoadGrpcServerConfig()
- func (s *Service) LoadRequiredConfig()
- func (s *Service) Name() string
- func (s *Service) RegisterDiscovery(ctx context.Context)
- func (s *Service) Run(run RunFunc)
- func (s *Service) Scheduler() *sync.WaitGroup
- func (s *Service) ServeGRPC(ctx context.Context, srv grpc.ServiceServer)
- func (s *Service) StartDiscovery(ctx context.Context) error
Constants ¶
const ( ExitOK = iota ExitError ExitStartup )
const (
// Max no. of discovery register retries.
MaxDiscoveryRetries = 3
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RunFunc ¶
RunFunc is a function that will be called by Run to initialize a service. If this function returns an error then the server will immediately shut down.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a platform application.
func (*Service) Creds ¶
func (s *Service) Creds() *credentials.Store
func (*Service) Error ¶
Error sends a given error to the Service's error channel. Services should prefer calling this method instead of manually calling s.Exit() so shutdown can be handled gracefully.
func (*Service) Exit ¶
Exit cancels the service's context in order to signal a shutdown to child processes. It sleeps for a configurable time before signalling the process to exit.
func (*Service) LoadCredentials ¶
func (s *Service) LoadCredentials(creds ...credentials.Credential)
LoadCredentials attempts to load service credentials from config values into the credentials store. As this method is intended to be ran before service startup, errors are treated as fatal.
func (*Service) LoadDiscoveryConfig ¶
func (s *Service) LoadDiscoveryConfig()
LoadDiscoveryConfig is a helper function for loading service discovery config.
func (*Service) LoadGrpcClientConfig ¶
func (s *Service) LoadGrpcClientConfig()
LoadGrpcClientConfig is a helper function for loading required gRPC server config.
func (*Service) LoadGrpcServerConfig ¶
func (s *Service) LoadGrpcServerConfig()
LoadGrpcServerConfig is a helper function for loading required gRPC server config.
func (*Service) LoadRequiredConfig ¶
func (s *Service) LoadRequiredConfig()
LoadRequiredConfig is a helper function for loading config required by a service.
func (*Service) RegisterDiscovery ¶
RegisterDiscovery attempts to periodically register a service with the discovery service.
func (*Service) Run ¶
Run starts the Service and ensures all dependencies are initialised.
By default, it will start the local web server and wait for a stop signal to be received before attempting to gracefully shutdown.