jsonrpc: lint fixes

This commit is contained in:
Łukasz Magiera 2019-07-23 02:24:26 +02:00
parent 1b1ec2b812
commit 0d5d6cd1c2

View File

@ -44,7 +44,6 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
var handling = map[int64]context.CancelFunc{} var handling = map[int64]context.CancelFunc{}
var handlingLk sync.Mutex var handlingLk sync.Mutex
type outChanReg struct { type outChanReg struct {
id uint64 id uint64
ch reflect.Value ch reflect.Value
@ -60,7 +59,6 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
// chanHandlers is a map of client-side channel handlers // chanHandlers is a map of client-side channel handlers
chanHandlers := map[uint64]func(m []byte, ok bool){} chanHandlers := map[uint64]func(m []byte, ok bool){}
// nextMessage wait for one message and puts it to the incoming channel // nextMessage wait for one message and puts it to the incoming channel
nextMessage := func() { nextMessage := func() {
msgType, r, err := conn.NextReader() msgType, r, err := conn.NextReader()
@ -121,7 +119,7 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
Chan: regV, Chan: regV,
}, },
} }
var caseToId []uint64 var caseToID []uint64
for { for {
chosen, val, ok := reflect.Select(cases) chosen, val, ok := reflect.Select(cases)
@ -138,7 +136,7 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
registration := val.Interface().(outChanReg) registration := val.Interface().(outChanReg)
caseToId = append(caseToId, registration.id) caseToID = append(caseToID, registration.id)
cases = append(cases, reflect.SelectCase{ cases = append(cases, reflect.SelectCase{
Dir: reflect.SelectRecv, Dir: reflect.SelectRecv,
Chan: registration.ch, Chan: registration.ch,
@ -150,15 +148,15 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
if !ok { if !ok {
// Output channel closed, cleanup, and tell remote that this happened // Output channel closed, cleanup, and tell remote that this happened
n := len(caseToId) n := len(caseToID)
if n > 0 { if n > 0 {
cases[chosen] = cases[n] cases[chosen] = cases[n]
caseToId[chosen-1] = caseToId[n-1] caseToID[chosen-1] = caseToID[n-1]
} }
id := caseToId[chosen-1] id := caseToID[chosen-1]
cases = cases[:n] cases = cases[:n]
caseToId = caseToId[:n-1] caseToID = caseToID[:n-1]
sendReq(request{ sendReq(request{
Jsonrpc: "2.0", Jsonrpc: "2.0",
@ -174,7 +172,7 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
Jsonrpc: "2.0", Jsonrpc: "2.0",
ID: nil, // notification ID: nil, // notification
Method: chValue, Method: chValue,
Params: []param{{v: reflect.ValueOf(caseToId[chosen-1])}, {v: val}}, Params: []param{{v: reflect.ValueOf(caseToID[chosen-1])}, {v: val}},
}) })
} }
} }