From 0bcae125c20df24f5d592453d119ec0f4e0dc89c Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 12 Jan 2016 18:29:31 -0500 Subject: [PATCH] use comma separated string for arg names --- client/ws_client.go | 3 --- server/handlers.go | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/client/ws_client.go b/client/ws_client.go index ae2b324a4..4ce1ca07e 100644 --- a/client/ws_client.go +++ b/client/ws_client.go @@ -54,12 +54,10 @@ func (wsc *WSClient) dial() error { // Set the ping/pong handlers con.SetPingHandler(func(m string) error { // NOTE: https://github.com/gorilla/websocket/issues/97 - log.Debug("Client received ping, writing pong") go con.WriteControl(websocket.PongMessage, []byte(m), time.Now().Add(time.Second*wsWriteTimeoutSeconds)) return nil }) con.SetPongHandler(func(m string) error { - log.Debug("Client received pong") // NOTE: https://github.com/gorilla/websocket/issues/97 return nil }) @@ -74,7 +72,6 @@ func (wsc *WSClient) OnStop() { func (wsc *WSClient) receiveEventsRoutine() { for { - log.Notice("Waiting for wsc message ...") _, data, err := wsc.ReadMessage() if err != nil { log.Info("WSClient failed to read message", "error", err, "data", string(data)) diff --git a/server/handlers.go b/server/handlers.go index 64c151808..843a7ada8 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -9,6 +9,7 @@ import ( "net/http" "reflect" "sort" + "strings" "time" "github.com/gorilla/websocket" @@ -41,23 +42,26 @@ type RPCFunc struct { } // wraps a function for quicker introspection -func NewRPCFunc(f interface{}, args []string) *RPCFunc { - return &RPCFunc{ - f: reflect.ValueOf(f), - args: funcArgTypes(f), - returns: funcReturnTypes(f), - argNames: args, - ws: false, - } +// f is the function, args are comma separated argument names +func NewRPCFunc(f interface{}, args string) *RPCFunc { + return newRPCFunc(f, args, false) +} + +func NewWSRPCFunc(f interface{}, args string) *RPCFunc { + return newRPCFunc(f, args, true) } -func NewWSRPCFunc(f interface{}, args []string) *RPCFunc { +func newRPCFunc(f interface{}, args string, ws bool) *RPCFunc { + var argNames []string + if args != "" { + argNames = strings.Split(args, ",") + } return &RPCFunc{ f: reflect.ValueOf(f), args: funcArgTypes(f), returns: funcReturnTypes(f), - argNames: args, - ws: true, + argNames: argNames, + ws: ws, } }