feat(core-service): satisfy core lifecycle contract
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 07:16:16 +00:00
parent afe7b6e9de
commit 06a5fe9ac8
2 changed files with 12 additions and 3 deletions

View file

@ -21,6 +21,9 @@ type CoreService struct {
hookInstalled bool
}
var _ core.Startable = (*CoreService)(nil)
var _ core.Stoppable = (*CoreService)(nil)
func (s *CoreService) wrapped() *Service {
if s == nil {
return nil
@ -135,11 +138,16 @@ func NewCoreService(opts ServiceOptions) func(*core.Core) (any, error) {
}
// OnStartup initialises the i18n service.
func (s *CoreService) OnStartup(_ context.Context) error {
func (s *CoreService) OnStartup(_ context.Context) core.Result {
if svc := s.wrapped(); svc != nil && svc.Mode() == ModeCollect {
s.ensureMissingKeyCollector()
}
return nil
return core.Result{OK: true}
}
// OnShutdown finalises the i18n service.
func (s *CoreService) OnShutdown(_ context.Context) core.Result {
return core.Result{OK: true}
}
func (s *CoreService) ensureMissingKeyCollector() {

View file

@ -40,7 +40,8 @@ func TestCoreServiceNilSafe(t *testing.T) {
})
assert.Nil(t, defaultService.Load())
assert.NoError(t, svc.OnStartup(nil))
assert.Equal(t, core.Result{OK: true}, svc.OnStartup(nil))
assert.Equal(t, core.Result{OK: true}, svc.OnShutdown(nil))
svc.SetMode(ModeCollect)
svc.SetFallback("fr")
svc.SetFormality(FormalityFormal)