From fd40f9a82a732bb3db0f6e706ade7a9f991de6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 22 Jul 2019 22:28:40 +0200 Subject: [PATCH] jsonrpc: gofmt --- cli/cmd.go | 4 ++-- daemon/cmd.go | 1 + lib/jsonrpc/client.go | 9 ++++----- lib/jsonrpc/websocket.go | 25 +++++++++++++------------ node/api.go | 8 ++++---- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/cli/cmd.go b/cli/cmd.go index 7bfdbc826..adc4bfe8b 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -70,7 +70,7 @@ var Commands = []*cli.Command{ createMinerCmd, { - Name:"testch", + Name: "testch", Action: func(cctx *cli.Context) error { api, err := getAPI(cctx) if err != nil { @@ -87,7 +87,7 @@ var Commands = []*cli.Command{ select { case n := <-c: fmt.Println(n) - case <- ctx.Done(): + case <-ctx.Done(): return nil } } diff --git a/daemon/cmd.go b/daemon/cmd.go index a46264728..4029f581e 100644 --- a/daemon/cmd.go +++ b/daemon/cmd.go @@ -4,6 +4,7 @@ package daemon import ( "context" + "github.com/multiformats/go-multiaddr" "gopkg.in/urfave/cli.v2" diff --git a/lib/jsonrpc/client.go b/lib/jsonrpc/client.go index 97b9d943f..004123c4b 100644 --- a/lib/jsonrpc/client.go +++ b/lib/jsonrpc/client.go @@ -34,12 +34,11 @@ func (e *ErrClient) Unwrap(err error) error { return e.err } - type clientResponse struct { - Jsonrpc string `json:"jsonrpc"` - Result json.RawMessage `json:"result"` - ID int64 `json:"id"` - Error *respError `json:"error,omitempty"` + Jsonrpc string `json:"jsonrpc"` + Result json.RawMessage `json:"result"` + ID int64 `json:"id"` + Error *respError `json:"error,omitempty"` } type clientRequest struct { diff --git a/lib/jsonrpc/websocket.go b/lib/jsonrpc/websocket.go index 26d8cba6b..82dbe30cf 100644 --- a/lib/jsonrpc/websocket.go +++ b/lib/jsonrpc/websocket.go @@ -27,8 +27,8 @@ type frame struct { Params []param `json:"params,omitempty"` // response - Result json.RawMessage `json:"result,omitempty"` - Error *respError `json:"error,omitempty"` + Result json.RawMessage `json:"result,omitempty"` + Error *respError `json:"error,omitempty"` } func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, requests <-chan clientRequest, stop <-chan struct{}) { @@ -98,7 +98,10 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r var chOnce sync.Once var outId uint64 - type chReg struct { id uint64; ch reflect.Value } + type chReg struct { + id uint64 + ch reflect.Value + } registerCh := make(chan chReg) defer close(registerCh) @@ -107,13 +110,12 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r cases := []reflect.SelectCase{ { // registration chan always 0 - Dir: reflect.SelectRecv, + Dir: reflect.SelectRecv, Chan: regV, }, } var caseToId []uint64 - for { chosen, val, ok := reflect.Select(cases) @@ -129,19 +131,18 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r caseToId = append(caseToId, registration.id) cases = append(cases, reflect.SelectCase{ - Dir: reflect.SelectRecv, + Dir: reflect.SelectRecv, Chan: registration.ch, }) continue } - if !ok { n := len(caseToId) if n > 0 { cases[chosen] = cases[n] - caseToId[chosen - 1] = caseToId[n - 1] + caseToId[chosen-1] = caseToId[n-1] } cases = cases[:n] @@ -151,9 +152,9 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r sendReq(request{ Jsonrpc: "2.0", - ID: nil, // notification - Method: chValue, - Params: []param{{v: reflect.ValueOf(caseToId[chosen - 1])}, {v: val}}, + ID: nil, // notification + Method: chValue, + Params: []param{{v: reflect.ValueOf(caseToId[chosen-1])}, {v: val}}, }) } } @@ -184,7 +185,7 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r for id, req := range inflight { req.ready <- clientResponse{ Jsonrpc: "2.0", - ID: id, + ID: id, Error: &respError{ Message: "handler: websocket connection closed", }, diff --git a/node/api.go b/node/api.go index a1e6dfe8a..3745a50a8 100644 --- a/node/api.go +++ b/node/api.go @@ -39,10 +39,10 @@ func (a *API) TestCh(ctx context.Context) (<-chan int, error) { time.Sleep(time.Millisecond * 100) n++ select { - case <-ctx.Done(): - fmt.Println("CTXCANCEL!") - return - case out <- n: + case <-ctx.Done(): + fmt.Println("CTXCANCEL!") + return + case out <- n: } } }()