refactor: modernize codebase for Go 1.26 and fix adapter issues
- Upgrade Go version from 1.24 to 1.26.1 with updated dependencies
- Replace interface{} with any type throughout codebase
- Add message deduplication in OneBot11 adapter to prevent duplicate event processing
- URL-encode access token in WebSocket connections to handle special characters
- Remove duplicate bot startup hooks in DI providers (now handled by botManager.StartAll)
- Use slices.Clone and errgroup.Go patterns for cleaner concurrent code
- Apply omitzero JSON tags for optional fields (Go 1.24+ feature)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"slices"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -63,8 +64,7 @@ func NewEventBus(logger *zap.Logger, bufferSize int) *EventBus {
|
||||
|
||||
// Start 启动事件总线
|
||||
func (eb *EventBus) Start() {
|
||||
eb.wg.Add(1)
|
||||
go eb.dispatch()
|
||||
eb.wg.Go(eb.dispatch)
|
||||
eb.logger.Info("Event bus started")
|
||||
}
|
||||
|
||||
@@ -193,8 +193,6 @@ func (eb *EventBus) Unsubscribe(eventType protocol.EventType, ch chan protocol.E
|
||||
|
||||
// dispatch 分发事件到订阅者
|
||||
func (eb *EventBus) dispatch() {
|
||||
defer eb.wg.Done()
|
||||
|
||||
eb.logger.Info("Event bus dispatch loop started")
|
||||
|
||||
for {
|
||||
@@ -220,8 +218,7 @@ func (eb *EventBus) dispatchEvent(event protocol.Event) {
|
||||
key := string(event.GetType())
|
||||
subs := eb.subscriptions[key]
|
||||
// 复制订阅者列表避免锁竞争
|
||||
subsCopy := make([]*Subscription, len(subs))
|
||||
copy(subsCopy, subs)
|
||||
subsCopy := slices.Clone(subs)
|
||||
eb.mu.RUnlock()
|
||||
|
||||
eb.logger.Info("Dispatching event",
|
||||
|
||||
Reference in New Issue
Block a user