allow unsplit command registrations
This commit is contained in:
parent
76f95a422b
commit
6443443c6b
2 changed files with 10 additions and 7 deletions
|
@ -30,7 +30,7 @@ type WebSocketManager interface {
|
|||
// cmd is the first part, before first slash
|
||||
// dataNew is a function to create a new message datatype
|
||||
RegisterWSCommand(cmd string, hnd Handler, dataNew NewData)
|
||||
WSCommandHandler(cmd string) (NewData, Handler, error)
|
||||
WSCommandHandler(cmd string, splitCmd []string) (NewData, Handler, error)
|
||||
}
|
||||
|
||||
type WebSocketSession interface {
|
||||
|
|
|
@ -62,13 +62,16 @@ func (wsm *wsManager) RegisterWSCommand(cmd string, hnd core.Handler, dataNew co
|
|||
}
|
||||
}
|
||||
|
||||
func (wsm *wsManager) WSCommandHandler(cmd string) (core.NewData, core.Handler, error) {
|
||||
wse, ok := wsm.r[cmd]
|
||||
if !ok {
|
||||
return nil, nil, NoSuchHandlerErr
|
||||
func (wsm *wsManager) WSCommandHandler(cmd string, cmdSplit []string) (core.NewData, core.Handler, error) {
|
||||
if wse, ok := wsm.r[cmd]; ok {
|
||||
return wse.dataNew, wse.hnd, nil
|
||||
}
|
||||
|
||||
if wse, ok := wsm.r[cmdSplit[0]]; ok {
|
||||
return wse.dataNew, wse.hnd, nil
|
||||
}
|
||||
|
||||
return nil, nil, NoSuchHandlerErr
|
||||
}
|
||||
|
||||
func NewManager() core.WebSocketManager {
|
||||
|
@ -173,7 +176,7 @@ func (ws *cmdHandler) handleMsg(r io.Reader) error {
|
|||
|
||||
cmd := strings.Split(msgType, "/")
|
||||
|
||||
newData, hand, err := ws.b.WSCommandHandler(cmd[0])
|
||||
newData, hand, err := ws.b.WSCommandHandler(cmd[0], cmd)
|
||||
switch err {
|
||||
case nil:
|
||||
case NoSuchHandlerErr:
|
||||
|
|
Loading…
Reference in a new issue