Use context everywhere
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user