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.

37 lines
633 B
Go

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)
}
}