Documentation
¶
Index ¶
- Variables
- func ResetInstance()
- type AllowedFailure
- type AllowedFailureMockService
- type Commander
- type Dependent
- type DependentMockService
- type FullMockService
- func (f *FullMockService) Dependencies() []string
- func (f *FullMockService) IsAllowedFailure() bool
- func (f *FullMockService) MaxRetries() int
- func (f *FullMockService) RetryDelay() time.Duration
- func (f *FullMockService) WithAllowFailure(v bool) *FullMockService
- func (f *FullMockService) WithDependencies(deps ...string) *FullMockService
- func (f *FullMockService) WithMaxRetries(n int) *FullMockService
- func (f *FullMockService) WithRetryDelay(d time.Duration) *FullMockService
- type MockService
- func (m *MockService) IsRunning() bool
- func (m *MockService) Name() string
- func (m *MockService) Run(ctx context.Context) error
- func (m *MockService) RunCount() int
- func (m *MockService) Stop(_ context.Context) error
- func (m *MockService) WasRunCalled() bool
- func (m *MockService) WasStopCalled() bool
- func (m *MockService) WithOnRun(fn func()) *MockService
- func (m *MockService) WithRunDelay(delay time.Duration) *MockService
- func (m *MockService) WithRunError(err error) *MockService
- func (m *MockService) WithRunErrors(errs ...error) *MockService
- func (m *MockService) WithStopError(err error) *MockService
- type ReadyMockService
- type ReadyNotifier
- type Retryable
- type RetryableMockService
- type Service
- type ServiceFactory
- type ServiceManager
- func (s *ServiceManager) Add(services ...Service)
- func (s *ServiceManager) ClearServices()
- func (s *ServiceManager) Commands() []*cobra.Command
- func (s *ServiceManager) Instantiate(name string) (Service, error)
- func (s *ServiceManager) Register(name string, factory ServiceFactory)
- func (s *ServiceManager) RegisteredNames() []string
- func (s *ServiceManager) Run(ctx context.Context) error
- func (s *ServiceManager) Stop(ctx context.Context)
- type TestService
Constants ¶
This section is empty.
Variables ¶
var ( ErrServiceNotFound = errors.New("service not found") ErrNoEnabledServices = errors.New("no enabled services") ErrCyclicDependency = errors.New("cyclic dependency detected") ErrDependencyNotFound = errors.New("dependency not found") ErrMaxRetriesReached = errors.New("max retries reached") ErrStopTimeout = errors.New("service stop timed out") ErrServicePanic = errors.New("service panicked") ErrNoCommands = errors.New("service has no commands") )
Functions ¶
func ResetInstance ¶
func ResetInstance()
Types ¶
type AllowedFailure ¶
type AllowedFailure interface {
IsAllowedFailure() bool
}
AllowedFailure is optionally implemented by services whose failure should not bring down the entire service manager.
type AllowedFailureMockService ¶
type AllowedFailureMockService struct {
*MockService
}
func NewAllowedFailureMockService ¶
func NewAllowedFailureMockService( name string, ) *AllowedFailureMockService
func (*AllowedFailureMockService) IsAllowedFailure ¶
func (a *AllowedFailureMockService) IsAllowedFailure() bool
type Commander ¶
Commander is optionally implemented by services that expose CLI subcommands. The returned commands are added under the service name: ./app <servicename> <subcommand>.
type Dependent ¶
type Dependent interface {
Dependencies() []string
}
Dependent is optionally implemented by services that must start after other services. Dependencies returns the names of services this service depends on.
type DependentMockService ¶
type DependentMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewDependentMockService ¶
func NewDependentMockService( name string, deps ...string, ) *DependentMockService
func (*DependentMockService) Dependencies ¶
func (d *DependentMockService) Dependencies() []string
type FullMockService ¶
type FullMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewFullMockService ¶
func NewFullMockService(name string) *FullMockService
func (*FullMockService) Dependencies ¶
func (f *FullMockService) Dependencies() []string
func (*FullMockService) IsAllowedFailure ¶
func (f *FullMockService) IsAllowedFailure() bool
func (*FullMockService) MaxRetries ¶
func (f *FullMockService) MaxRetries() int
func (*FullMockService) RetryDelay ¶
func (f *FullMockService) RetryDelay() time.Duration
func (*FullMockService) WithAllowFailure ¶
func (f *FullMockService) WithAllowFailure( v bool, ) *FullMockService
func (*FullMockService) WithDependencies ¶
func (f *FullMockService) WithDependencies( deps ...string, ) *FullMockService
func (*FullMockService) WithMaxRetries ¶
func (f *FullMockService) WithMaxRetries( n int, ) *FullMockService
func (*FullMockService) WithRetryDelay ¶
func (f *FullMockService) WithRetryDelay( d time.Duration, ) *FullMockService
type MockService ¶
type MockService struct {
// contains filtered or unexported fields
}
func NewMockService ¶
func NewMockService(name string) *MockService
func (*MockService) IsRunning ¶
func (m *MockService) IsRunning() bool
func (*MockService) Name ¶
func (m *MockService) Name() string
func (*MockService) RunCount ¶
func (m *MockService) RunCount() int
func (*MockService) WasRunCalled ¶
func (m *MockService) WasRunCalled() bool
func (*MockService) WasStopCalled ¶
func (m *MockService) WasStopCalled() bool
func (*MockService) WithOnRun ¶
func (m *MockService) WithOnRun( fn func(), ) *MockService
func (*MockService) WithRunDelay ¶
func (m *MockService) WithRunDelay( delay time.Duration, ) *MockService
func (*MockService) WithRunError ¶
func (m *MockService) WithRunError( err error, ) *MockService
func (*MockService) WithRunErrors ¶
func (m *MockService) WithRunErrors( errs ...error, ) *MockService
func (*MockService) WithStopError ¶
func (m *MockService) WithStopError( err error, ) *MockService
type ReadyMockService ¶
type ReadyMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewReadyMockService ¶
func NewReadyMockService( name string, deps ...string, ) *ReadyMockService
func (*ReadyMockService) Dependencies ¶
func (r *ReadyMockService) Dependencies() []string
func (*ReadyMockService) Ready ¶
func (r *ReadyMockService) Ready() <-chan struct{}
func (*ReadyMockService) SignalReady ¶
func (r *ReadyMockService) SignalReady()
type ReadyNotifier ¶
type ReadyNotifier interface {
Ready() <-chan struct{}
}
ReadyNotifier is optionally implemented by services that need to signal when they're actually ready to serve. The service manager waits for the Ready channel to close before starting dependent services. Services that don't implement this are considered ready immediately after their goroutine is launched.
type Retryable ¶
Retryable is optionally implemented by services that want automatic restart on failure. MaxRetries returns the maximum number of retry attempts (0 means no retries). RetryDelay returns the delay between retries. Use human-readable durations like 1s, 2m, 1h30m via time.Duration.
type RetryableMockService ¶
type RetryableMockService struct {
*MockService
// contains filtered or unexported fields
}
func NewRetryableMockService ¶
func NewRetryableMockService( name string, maxRetries int, ) *RetryableMockService
func (*RetryableMockService) MaxRetries ¶
func (r *RetryableMockService) MaxRetries() int
func (*RetryableMockService) RetryDelay ¶
func (r *RetryableMockService) RetryDelay() time.Duration
func (*RetryableMockService) WithRetryDelay ¶
func (r *RetryableMockService) WithRetryDelay( d time.Duration, ) *RetryableMockService
type ServiceFactory ¶
ServiceFactory is a function that creates a service instance.
type ServiceManager ¶
type ServiceManager struct {
// contains filtered or unexported fields
}
func GetInstance ¶
func GetInstance() *ServiceManager
func (*ServiceManager) Add ¶
func (s *ServiceManager) Add(services ...Service)
func (*ServiceManager) ClearServices ¶
func (s *ServiceManager) ClearServices()
func (*ServiceManager) Commands ¶
func (s *ServiceManager) Commands() []*cobra.Command
Commands returns lazy cobra commands for each registered service factory. Each parent command instantiates only its own service when invoked, so ./app <service> <subcommand> doesn't trigger initialization of all services.
func (*ServiceManager) Instantiate ¶
func (s *ServiceManager) Instantiate( name string, ) (Service, error)
func (*ServiceManager) Register ¶
func (s *ServiceManager) Register( name string, factory ServiceFactory, )
Register stores a service factory for lazy instantiation. The factory is only called when the service is actually needed (during Run or when a Commander command is invoked).
func (*ServiceManager) RegisteredNames ¶
func (s *ServiceManager) RegisteredNames() []string
RegisteredNames returns the names of all registered service factories.
func (*ServiceManager) Stop ¶
func (s *ServiceManager) Stop(ctx context.Context)
type TestService ¶
type TestService struct {
// contains filtered or unexported fields
}
func NewTestService ¶
func NewTestService(name string) *TestService
func (*TestService) Name ¶
func (s *TestService) Name() string