From 6443443c6bd549b27a6f99cbc378bddd386801da Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 20 Dec 2022 20:34:45 -0500 Subject: [PATCH] allow unsplit command registrations --- pkg/blas/core/core.go | 2 +- pkg/wsapi/api.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/blas/core/core.go b/pkg/blas/core/core.go index 5784368..d5ef63c 100644 --- a/pkg/blas/core/core.go +++ b/pkg/blas/core/core.go @@ -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 { diff --git a/pkg/wsapi/api.go b/pkg/wsapi/api.go index 454f807..b4f0d8e 100644 --- a/pkg/wsapi/api.go +++ b/pkg/wsapi/api.go @@ -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 } - 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: