package command import ( "dcg/game/pb" "strings" ) type HandlerFunc func(cmd string, user *pb.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(cmd string, user *pb.User) { if len(cmd) < 0 { return } fChar := cmd[0] c := strings.ToLower(string(fChar)) if h, ok := m.handlers[c]; ok { h(cmd, user) } }