(Engine) Variety of engine updates (#390)

* drop common uuid v4 func and imported package as needed

* removed common functions regarding json marshal and unmarshal and used the json package directly. WRT unmarshal it was calling reflect and converted to string which is also checked in the JSON package so it was doing a double up, this will be a tiny gain as it was directly used in the requester package for all our outbound requests.

* add in string

* explicitly throw away return error value

* atleast return the error that websocket initialise returns

* return error when not connected

* fix comment

* Adds comments

* move package declarations

* drop append whenever we call supported

* remove unused import

* Change incorrect spelling

* fix tests

* fix go import issue
This commit is contained in:
Ryan O'Hara-Reid
2019-12-03 10:06:08 +11:00
committed by Adrian Gallagher
parent c27b8657e2
commit 0c5d75b22c
70 changed files with 393 additions and 462 deletions

View File

@@ -1,12 +1,12 @@
package engine
import (
"encoding/json"
"errors"
"net/http"
"strings"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
@@ -79,7 +79,7 @@ func (h *WebsocketHub) run() {
// SendWebsocketMessage sends a websocket event to the client
func (c *WebsocketClient) SendWebsocketMessage(evt interface{}) error {
data, err := common.JSONEncode(evt)
data, err := json.Marshal(evt)
if err != nil {
log.Errorf(log.WebsocketMgr, "websocket: failed to send message: %s\n", err)
return err
@@ -106,7 +106,7 @@ func (c *WebsocketClient) read() {
if msgType == websocket.TextMessage {
var evt WebsocketEvent
err := common.JSONDecode(message, &evt)
err := json.Unmarshal(message, &evt)
if err != nil {
log.Errorf(log.WebsocketMgr, "websocket: failed to decode JSON sent from client %s\n", err)
continue
@@ -117,7 +117,7 @@ func (c *WebsocketClient) read() {
continue
}
dataJSON, err := common.JSONEncode(evt.Data)
dataJSON, err := json.Marshal(evt.Data)
if err != nil {
log.Errorln(log.WebsocketMgr, "websocket: client sent data we couldn't JSON decode")
break
@@ -197,7 +197,7 @@ func BroadcastWebsocketMessage(evt WebsocketEvent) error {
return errors.New("websocket service not started")
}
data, err := common.JSONEncode(evt)
data, err := json.Marshal(evt)
if err != nil {
return err
}
@@ -257,7 +257,7 @@ func wsAuth(client *WebsocketClient, data interface{}) error {
}
var auth WebsocketAuth
err := common.JSONDecode(data.([]byte), &auth)
err := json.Unmarshal(data.([]byte), &auth)
if err != nil {
wsResp.Error = err.Error()
client.SendWebsocketMessage(wsResp)
@@ -303,7 +303,7 @@ func wsSaveConfig(client *WebsocketClient, data interface{}) error {
Event: "SaveConfig",
}
var cfg config.Config
err := common.JSONDecode(data.([]byte), &cfg)
err := json.Unmarshal(data.([]byte), &cfg)
if err != nil {
wsResp.Error = err.Error()
client.SendWebsocketMessage(wsResp)
@@ -344,7 +344,7 @@ func wsGetTicker(client *WebsocketClient, data interface{}) error {
Event: "GetTicker",
}
var tickerReq WebsocketOrderbookTickerRequest
err := common.JSONDecode(data.([]byte), &tickerReq)
err := json.Unmarshal(data.([]byte), &tickerReq)
if err != nil {
wsResp.Error = err.Error()
client.SendWebsocketMessage(wsResp)
@@ -376,7 +376,7 @@ func wsGetOrderbook(client *WebsocketClient, data interface{}) error {
Event: "GetOrderbook",
}
var orderbookReq WebsocketOrderbookTickerRequest
err := common.JSONDecode(data.([]byte), &orderbookReq)
err := json.Unmarshal(data.([]byte), &orderbookReq)
if err != nil {
wsResp.Error = err.Error()
client.SendWebsocketMessage(wsResp)