package command import ( pushPb "dcg/game/pb/push" ) type HandlerFunc func(roomId int64, cmd string, user *pushPb.PushUser) 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 *pushPb.PushUser) { if h, ok := m.handlers[cmd]; ok { h(roomId, cmd, user) } }