Documentation
¶
Overview ¶
Package service implements the Service type. This type is the core of the Mu framework.
Service is based on the concept of hooks and workers. Hooks are functions that are invoked at various points in the service lifecycle. Workers are goroutines that are started and stopped as part of the service lifecycle.
Service also contains some core functionality that is useful for most services. This includes logging, configuration, and signal handling.
Index ¶
- type CleanupFunc
- type Hooks
- type Option
- type PreRunFunc
- type Service
- func (s *Service) Cancel()
- func (s *Service) Cleanup(f CleanupFunc)
- func (s *Service) Config() config.Config
- func (s *Service) Context() context.Context
- func (s *Service) Logger() logging.Logger
- func (s *Service) Main() error
- func (s *Service) MainCommand() *cobra.Command
- func (s *Service) MockMode() bool
- func (s *Service) Name() string
- func (s *Service) Run() (status error)
- func (s *Service) Version() string
- type SetupConfigFunc
- type SetupHTTPFunc
- type SetupWorkersFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hooks ¶ added in v0.1.5
type Hooks interface { PreRun(f PreRunFunc) SetupConfig(f SetupConfigFunc) SetupWorkers(f SetupWorkersFunc) SetupHTTP(f SetupHTTPFunc, opts ...http.ServerOption) // contains filtered or unexported methods }
type Option ¶
Option is an option for a service.
func WithLogger ¶
WithLogger returns an option that sets the func used to create a new logger.
func WithMockMode ¶
func WithMockMode() Option
WithMockMode returns an option that sets the mock mode of the service.
func WithVersion ¶
WithVersion returns an option that sets the version of the service.
type PreRunFunc ¶ added in v0.1.10
type PreRunFunc func() error
PreRunFunc is a function that runs before the workers are started.
type Service ¶
type Service struct { // hooks are the hooks for the service. Hooks // contains filtered or unexported fields }
Service represents a service.
func (*Service) Cleanup ¶ added in v0.1.14
func (s *Service) Cleanup(f CleanupFunc)
Cleanup registers a cleanup function that is invoked when the service is stopped. Multiple cleanup functions can be registered. Cleanups are invoked in the reverse order they are registered.
func (*Service) Main ¶
Main invokes the main cobra.Command for the service. If you need to customize the command, see MainCommand.
func (*Service) MainCommand ¶
MainCommand returns the main cobra.Command for the service. This allows you to customize the command (perhaps adding flags) before invoking it with Execute.
type SetupConfigFunc ¶ added in v0.1.11
SetupConfigFunc is a function that sets up a service configuration.
type SetupHTTPFunc ¶ added in v0.1.5
SetupHTTPFunc is a function that sets up a service HTTP server.
type SetupWorkersFunc ¶ added in v0.1.10
SetupWorkersFunc is a function that sets up workers for the service.