package danmaku import pbMq "live-service/app/user_center/pb/mq" type HandlerFunc func(roomId int64, cmd string, dm *pbMq.MqDanmaku) type Manager struct { handlers map[string]HandlerFunc } func NewManager() *Manager { return &Manager{ handlers: make(map[string]HandlerFunc), } } func (m *Manager) Register(h HandlerFunc, cmd string, alias ...string) { if _, ok := m.handlers[cmd]; ok { return } m.handlers[cmd] = h // alias for _, s := range alias { if _, ok := m.handlers[cmd]; ok { continue } m.handlers[s] = h } } func (m *Manager) Handle(roomId int64, cmd string, user *pbMq.MqDanmaku) { if h, ok := m.handlers[cmd]; ok { h(roomId, cmd, user) } }