use comma separated string for arg names

This commit is contained in:
Ethan Buchman 2016-01-12 18:29:31 -05:00
parent 3d59e13dd8
commit 0bcae125c2
2 changed files with 15 additions and 14 deletions

View File

@ -54,12 +54,10 @@ func (wsc *WSClient) dial() error {
// Set the ping/pong handlers // Set the ping/pong handlers
con.SetPingHandler(func(m string) error { con.SetPingHandler(func(m string) error {
// NOTE: https://github.com/gorilla/websocket/issues/97 // 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)) go con.WriteControl(websocket.PongMessage, []byte(m), time.Now().Add(time.Second*wsWriteTimeoutSeconds))
return nil return nil
}) })
con.SetPongHandler(func(m string) error { con.SetPongHandler(func(m string) error {
log.Debug("Client received pong")
// NOTE: https://github.com/gorilla/websocket/issues/97 // NOTE: https://github.com/gorilla/websocket/issues/97
return nil return nil
}) })
@ -74,7 +72,6 @@ func (wsc *WSClient) OnStop() {
func (wsc *WSClient) receiveEventsRoutine() { func (wsc *WSClient) receiveEventsRoutine() {
for { for {
log.Notice("Waiting for wsc message ...")
_, data, err := wsc.ReadMessage() _, data, err := wsc.ReadMessage()
if err != nil { if err != nil {
log.Info("WSClient failed to read message", "error", err, "data", string(data)) log.Info("WSClient failed to read message", "error", err, "data", string(data))

View File

@ -9,6 +9,7 @@ import (
"net/http" "net/http"
"reflect" "reflect"
"sort" "sort"
"strings"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -41,23 +42,26 @@ type RPCFunc struct {
} }
// wraps a function for quicker introspection // wraps a function for quicker introspection
func NewRPCFunc(f interface{}, args []string) *RPCFunc { // f is the function, args are comma separated argument names
return &RPCFunc{ func NewRPCFunc(f interface{}, args string) *RPCFunc {
f: reflect.ValueOf(f), return newRPCFunc(f, args, false)
args: funcArgTypes(f),
returns: funcReturnTypes(f),
argNames: args,
ws: false,
}
} }
func NewWSRPCFunc(f interface{}, args []string) *RPCFunc { func NewWSRPCFunc(f interface{}, args string) *RPCFunc {
return newRPCFunc(f, args, true)
}
func newRPCFunc(f interface{}, args string, ws bool) *RPCFunc {
var argNames []string
if args != "" {
argNames = strings.Split(args, ",")
}
return &RPCFunc{ return &RPCFunc{
f: reflect.ValueOf(f), f: reflect.ValueOf(f),
args: funcArgTypes(f), args: funcArgTypes(f),
returns: funcReturnTypes(f), returns: funcReturnTypes(f),
argNames: args, argNames: argNames,
ws: true, ws: ws,
} }
} }