This commit is contained in:
crusader 2017-08-28 16:57:30 +09:00
parent 8a0c8265ee
commit 24629d21f6
3 changed files with 11 additions and 5 deletions

View File

@ -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() {

View File

@ -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"`
}

View File

@ -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()
}
}
}