You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
683 B
Go
36 lines
683 B
Go
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)
|
|
}
|
|
}
|