Initial commit
This commit is contained in:
commit
c5111cb551
20 changed files with 1764 additions and 0 deletions
39
modules/main.go
Normal file
39
modules/main.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue