allow unsplit command registrations

This commit is contained in:
Daniel Ponte 2022-12-20 20:34:45 -05:00
parent 76f95a422b
commit 6443443c6b
2 changed files with 10 additions and 7 deletions

View file

@ -30,7 +30,7 @@ type WebSocketManager interface {
// cmd is the first part, before first slash // cmd is the first part, before first slash
// dataNew is a function to create a new message datatype // dataNew is a function to create a new message datatype
RegisterWSCommand(cmd string, hnd Handler, dataNew NewData) RegisterWSCommand(cmd string, hnd Handler, dataNew NewData)
WSCommandHandler(cmd string) (NewData, Handler, error) WSCommandHandler(cmd string, splitCmd []string) (NewData, Handler, error)
} }
type WebSocketSession interface { type WebSocketSession interface {

View file

@ -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) { func (wsm *wsManager) WSCommandHandler(cmd string, cmdSplit []string) (core.NewData, core.Handler, error) {
wse, ok := wsm.r[cmd] if wse, ok := wsm.r[cmd]; ok {
if !ok { return wse.dataNew, wse.hnd, nil
return nil, nil, NoSuchHandlerErr
} }
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 { func NewManager() core.WebSocketManager {
@ -173,7 +176,7 @@ func (ws *cmdHandler) handleMsg(r io.Reader) error {
cmd := strings.Split(msgType, "/") cmd := strings.Split(msgType, "/")
newData, hand, err := ws.b.WSCommandHandler(cmd[0]) newData, hand, err := ws.b.WSCommandHandler(cmd[0], cmd)
switch err { switch err {
case nil: case nil:
case NoSuchHandlerErr: case NoSuchHandlerErr: