package command import ( pushPb "dcg/game/pb/push" "strings" ) type HandlerFunc func(roomId int64, cmd string, user *pushPb.User) type Manager struct { handlers map[string]HandlerFunc } func NewManager() *Manager { return &Manager{ handlers: make(map[string]HandlerFunc), } } func (m *Manager) Register(cmd string, h HandlerFunc) { if _, ok := m.handlers[cmd]; ok { return } m.handlers[cmd] = h } func (m *Manager) Handle(roomId int64, cmd string, user *pushPb.User) { if len(cmd) < 0 { return } fChar := cmd[0] c := strings.ToLower(string(fChar)) if h, ok := m.handlers[c]; ok { h(roomId, cmd, user) } }