Use context everywhere

This commit is contained in:
2026-05-26 18:58:50 +03:00
parent 3ece07e11d
commit 11a357ebc4
7 changed files with 37 additions and 54 deletions

View File

@@ -13,10 +13,8 @@ import (
)
type App struct {
ctx context.Context
logger *logrus.Entry
config *configuration.Config
wg *sync.WaitGroup
domains map[string]domains.Domain
domainsMutex sync.RWMutex
@@ -26,10 +24,6 @@ func (a *App) Config() *configuration.Config {
return a.config
}
func (a *App) Context() context.Context {
return a.ctx
}
func (a *App) Logger() *logrus.Entry {
return a.logger
}
@@ -54,8 +48,6 @@ func New(ctx context.Context) *App {
"numgc": strconv.FormatUint(uint64(m.NumGC), 10),
})
app.ctx = ctx
app.domains = make(map[string]domains.Domain)
return app
@@ -92,12 +84,12 @@ func (a *App) RetrieveDomain(name string) any {
return a.domains[name]
}
func (a *App) ConnectDependencies() error {
func (a *App) ConnectDependencies(ctx context.Context) error {
a.domainsMutex.RLock()
defer a.domainsMutex.RUnlock()
for _, domain := range a.domains {
err := domain.ConnectDependencies()
err := domain.ConnectDependencies(ctx)
if err != nil {
return fmt.Errorf("%w: %w (%w)", ErrApplication, ErrConnectDependencies, err)
}
@@ -106,12 +98,12 @@ func (a *App) ConnectDependencies() error {
return nil
}
func (a *App) StartDomains() error {
func (a *App) StartDomains(ctx context.Context) error {
a.domainsMutex.RLock()
defer a.domainsMutex.RUnlock()
for _, domain := range a.domains {
err := domain.Start()
err := domain.Start(ctx)
if err != nil {
return fmt.Errorf("%w: %w (%w)", ErrApplication, ErrDomainInit, err)
}
@@ -119,11 +111,3 @@ func (a *App) StartDomains() error {
return nil
}
func (a *App) RegisterGlobalWaitGroup(wg *sync.WaitGroup) {
a.wg = wg
}
func (a *App) GetGlobalWaitGroup() *sync.WaitGroup {
return a.wg
}