From 24629d21f6f753bc3867a35d652b7de890be53b2 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 28 Aug 2017 16:57:30 +0900 Subject: [PATCH] ing --- protocol/jsonrpc/server_request.go | 4 ++-- protocol/jsonrpc/server_response.go | 6 +++--- server.go | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/protocol/jsonrpc/server_request.go b/protocol/jsonrpc/server_request.go index 6878f3c..dc6348f 100644 --- a/protocol/jsonrpc/server_request.go +++ b/protocol/jsonrpc/server_request.go @@ -6,8 +6,8 @@ import ( type ServerRequest struct { Method string `json:"method"` - Params *json.RawMessage `json:"params"` - Id *json.RawMessage `json:"id"` + Params []string `json:"params,omitempty"` + Id *json.RawMessage `json:"id,omitempty"` } func (r *ServerRequest) reset() { diff --git a/protocol/jsonrpc/server_response.go b/protocol/jsonrpc/server_response.go index d02d783..4bd72d9 100644 --- a/protocol/jsonrpc/server_response.go +++ b/protocol/jsonrpc/server_response.go @@ -5,7 +5,7 @@ import ( ) type ServerResponse struct { - Id *json.RawMessage `json:"id"` - Result interface{} `json:"result"` - Error interface{} `json:"error"` + Id *json.RawMessage `json:"id,omitempty"` + Result interface{} `json:"result,omitempty"` + Error interface{} `json:"error,omitempty"` } diff --git a/server.go b/server.go index 0576454..c3d6a9b 100644 --- a/server.go +++ b/server.go @@ -2,6 +2,7 @@ package overflow_gateway_websocket import ( "net/http" + "sync" "git.loafle.net/overflow/overflow_gateway_websocket/websocket" "github.com/valyala/fasthttp" @@ -19,6 +20,7 @@ type server struct { _upgrader *websocket.Upgrader _handlers map[string]*SocketOptions _sockets map[string]Socket + _socketsMtx sync.Mutex _addSocketCh chan Socket _removeSocketCh chan Socket } @@ -91,11 +93,15 @@ func (s *server) listenHandler() { select { // Add new a socket case soc := <-s._addSocketCh: + s._socketsMtx.Lock() s._sockets[soc.ID()] = soc + s._socketsMtx.Unlock() // remove a socket case soc := <-s._removeSocketCh: + s._socketsMtx.Lock() delete(s._sockets, soc.ID()) + s._socketsMtx.Unlock() } } }