Initial commit

This commit is contained in:
Djuri 2025-05-18 23:54:04 +02:00
commit c5111cb551
Signed by: djuri
GPG key ID: 61B9B2DDE5AA3AC1
20 changed files with 1764 additions and 0 deletions

39
modules/main.go Normal file
View file

@ -0,0 +1,39 @@
package modules
import (
"btclock/broker"
"context"
"sync"
)
type Module interface {
Init(broker *broker.EventBroker) error
Start(ctx context.Context) error
Stop() error
ID() string
}
type ModuleRegistry struct {
modules map[string]Module
mu sync.RWMutex
}
var Registry = &ModuleRegistry{
modules: make(map[string]Module),
}
func (b *ModuleRegistry) Register(module Module) {
b.mu.Lock()
defer b.mu.Unlock()
b.modules[module.ID()] = module
}
func (b *ModuleRegistry) GetAllModules() []Module {
b.mu.RLock()
defer b.mu.RUnlock()
modules := make([]Module, 0, len(b.modules))
for _, module := range b.modules {
modules = append(modules, module)
}
return modules
}