chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// EventBusAdapter adapts *EventBus to types.EventBusInterface
|
||||
// This allows EventBus to be used through the interface without circular dependencies
|
||||
type EventBusAdapter struct {
|
||||
bus *EventBus
|
||||
}
|
||||
|
||||
// NewEventBusAdapter creates a new adapter for EventBus
|
||||
func NewEventBusAdapter(bus *EventBus) types.EventBusInterface {
|
||||
return &EventBusAdapter{bus: bus}
|
||||
}
|
||||
|
||||
// On registers an event handler for a specific event type
|
||||
func (a *EventBusAdapter) On(eventType types.EventType, handler types.EventHandler) {
|
||||
// Convert types.EventType to event.EventType
|
||||
evtType := EventType(eventType)
|
||||
|
||||
// Convert types.EventHandler to event.EventHandler
|
||||
evtHandler := func(ctx context.Context, evt Event) error {
|
||||
// Convert event.Event to types.Event
|
||||
typesEvt := types.Event{
|
||||
ID: evt.ID,
|
||||
Type: types.EventType(evt.Type),
|
||||
SessionID: evt.SessionID,
|
||||
Data: evt.Data,
|
||||
Metadata: evt.Metadata,
|
||||
RequestID: evt.RequestID,
|
||||
}
|
||||
return handler(ctx, typesEvt)
|
||||
}
|
||||
|
||||
a.bus.On(evtType, evtHandler)
|
||||
}
|
||||
|
||||
// Emit publishes an event to all registered handlers
|
||||
func (a *EventBusAdapter) Emit(ctx context.Context, evt types.Event) error {
|
||||
// Convert types.Event to event.Event
|
||||
eventEvt := Event{
|
||||
ID: evt.ID,
|
||||
Type: EventType(evt.Type),
|
||||
SessionID: evt.SessionID,
|
||||
Data: evt.Data,
|
||||
Metadata: evt.Metadata,
|
||||
RequestID: evt.RequestID,
|
||||
}
|
||||
return a.bus.Emit(ctx, eventEvt)
|
||||
}
|
||||
|
||||
// AsEventBusInterface converts *EventBus to types.EventBusInterface
|
||||
func (eb *EventBus) AsEventBusInterface() types.EventBusInterface {
|
||||
return NewEventBusAdapter(eb)
|
||||
}
|
||||
Reference in new issue
Block a user