mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 15:11:10 +00:00
(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:
committed by
Adrian Gallagher
parent
c27b8657e2
commit
0c5d75b22c
@@ -82,7 +82,7 @@ func (s *Slack) PushEvent(event base.Event) error {
|
||||
return s.WebsocketSend("message",
|
||||
fmt.Sprintf("event: %s %s", event.Type, event.Message))
|
||||
}
|
||||
return nil
|
||||
return errors.New("slack not connected")
|
||||
}
|
||||
|
||||
// BuildURL returns an appended token string with the SlackURL
|
||||
@@ -212,7 +212,7 @@ func (s *Slack) WebsocketReader() {
|
||||
}
|
||||
|
||||
var data WebsocketResponse
|
||||
err = common.JSONDecode(resp, &data)
|
||||
err = json.Unmarshal(resp, &data)
|
||||
if err != nil {
|
||||
log.Errorln(log.CommunicationMgr, err)
|
||||
continue
|
||||
@@ -253,7 +253,7 @@ func (s *Slack) WebsocketReader() {
|
||||
|
||||
func (s *Slack) handlePresenceChange(resp []byte) error {
|
||||
var pres PresenceChange
|
||||
err := common.JSONDecode(resp, &pres)
|
||||
err := json.Unmarshal(resp, &pres)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error
|
||||
return errors.New("reply to is != 0")
|
||||
}
|
||||
var msg Message
|
||||
err := common.JSONDecode(resp, &msg)
|
||||
err := json.Unmarshal(resp, &msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func (s *Slack) handleReconnectResponse(resp []byte) error {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
var recURL reconnectResponse
|
||||
err := common.JSONDecode(resp, &recURL)
|
||||
err := json.Unmarshal(resp, &recURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package slack
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
)
|
||||
@@ -198,7 +198,7 @@ func TestHandlePresenceChange(t *testing.T) {
|
||||
t.Error("slack handlePresenceChange(), unmarshalled malformed json")
|
||||
}
|
||||
|
||||
data, _ := common.JSONEncode(pres)
|
||||
data, _ := json.Marshal(pres)
|
||||
err = s.handlePresenceChange(data)
|
||||
if err != nil {
|
||||
t.Errorf("slack handlePresenceChange() Error: %s", err)
|
||||
@@ -225,7 +225,7 @@ func TestHandleMessageResponse(t *testing.T) {
|
||||
var msg Message
|
||||
msg.User = "1337"
|
||||
msg.Text = "Hello World!"
|
||||
resp, _ := common.JSONEncode(msg)
|
||||
resp, _ := json.Marshal(msg)
|
||||
|
||||
err = s.handleMessageResponse(resp, data)
|
||||
if err != nil {
|
||||
@@ -233,7 +233,7 @@ func TestHandleMessageResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
msg.Text = "!notacommand"
|
||||
resp, _ = common.JSONEncode(msg)
|
||||
resp, _ = json.Marshal(msg)
|
||||
|
||||
err = s.handleMessageResponse(resp, data)
|
||||
if err == nil {
|
||||
@@ -270,7 +270,7 @@ func TestHandleReconnectResponse(t *testing.T) {
|
||||
}
|
||||
testURL.URL = "https://www.thrasher.io"
|
||||
|
||||
data, _ := common.JSONEncode(testURL)
|
||||
data, _ := json.Marshal(testURL)
|
||||
|
||||
err = s.handleReconnectResponse(data)
|
||||
if err != nil || s.ReconnectURL != "https://www.thrasher.io" {
|
||||
|
||||
Reference in New Issue
Block a user