Migrate from gometalinter.v2 to golangci-lint (#249)

* Migrate from gometalinter.v2 to golangci-lint
This commit is contained in:
Adrian Gallagher
2019-03-01 16:10:29 +11:00
committed by GitHub
parent 81852f2e01
commit 7dcb1ab553
133 changed files with 2179 additions and 2204 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
//global vars contain staged update data that will be sent to the communication
// global vars contain staged update data that will be sent to the communication
// mediums
var (
TickerStaged map[string]map[string]map[string]ticker.Price
@@ -92,9 +92,9 @@ func (b *Base) GetTicker(exchangeName string) string {
}
var tickerPrices []ticker.Price
for _, x := range tickerPrice {
for _, y := range x {
tickerPrices = append(tickerPrices, y)
for x := range tickerPrice {
for y := range tickerPrice[x] {
tickerPrices = append(tickerPrices, tickerPrice[x][y])
}
}

View File

@@ -14,7 +14,7 @@ type IComm []ICommunicate
// ICommunicate enforces standard functions across communication packages
type ICommunicate interface {
Setup(config config.CommunicationsConfig)
Setup(config *config.CommunicationsConfig)
Connect() error
PushEvent(Event) error
IsEnabled() bool
@@ -68,7 +68,7 @@ func (c IComm) GetEnabledCommunicationMediums() {
}
// StageTickerData stages updated ticker data for the communications package
func (c IComm) StageTickerData(exchangeName, assetType string, tickerPrice ticker.Price) {
func (c IComm) StageTickerData(exchangeName, assetType string, tickerPrice *ticker.Price) {
m.Lock()
defer m.Unlock()
@@ -80,12 +80,12 @@ func (c IComm) StageTickerData(exchangeName, assetType string, tickerPrice ticke
TickerStaged[exchangeName][assetType] = make(map[string]ticker.Price)
}
TickerStaged[exchangeName][assetType][tickerPrice.CurrencyPair] = tickerPrice
TickerStaged[exchangeName][assetType][tickerPrice.CurrencyPair] = *tickerPrice
}
// StageOrderbookData stages updated orderbook data for the communications
// package
func (c IComm) StageOrderbookData(exchangeName, assetType string, orderbook orderbook.Base) {
func (c IComm) StageOrderbookData(exchangeName, assetType string, ob *orderbook.Base) {
m.Lock()
defer m.Unlock()
@@ -97,12 +97,12 @@ func (c IComm) StageOrderbookData(exchangeName, assetType string, orderbook orde
OrderbookStaged[exchangeName][assetType] = make(map[string]Orderbook)
}
_, totalAsks := orderbook.CalculateTotalAsks()
_, totalBids := orderbook.CalculateTotalBids()
_, totalAsks := ob.CalculateTotalAsks()
_, totalBids := ob.CalculateTotalBids()
OrderbookStaged[exchangeName][assetType][orderbook.CurrencyPair] = Orderbook{
CurrencyPair: orderbook.CurrencyPair,
OrderbookStaged[exchangeName][assetType][ob.CurrencyPair] = Orderbook{
CurrencyPair: ob.CurrencyPair,
TotalAsks: totalAsks,
TotalBids: totalBids,
LastUpdated: orderbook.LastUpdated.String()}
LastUpdated: ob.LastUpdated.String()}
}

View File

@@ -15,30 +15,30 @@ type Communications struct {
}
// NewComm sets up and returns a pointer to a Communications object
func NewComm(config config.CommunicationsConfig) *Communications {
func NewComm(cfg *config.CommunicationsConfig) *Communications {
var comm Communications
if config.TelegramConfig.Enabled {
if cfg.TelegramConfig.Enabled {
Telegram := new(telegram.Telegram)
Telegram.Setup(config)
Telegram.Setup(cfg)
comm.IComm = append(comm.IComm, Telegram)
}
if config.SMSGlobalConfig.Enabled {
if cfg.SMSGlobalConfig.Enabled {
SMSGlobal := new(smsglobal.SMSGlobal)
SMSGlobal.Setup(config)
SMSGlobal.Setup(cfg)
comm.IComm = append(comm.IComm, SMSGlobal)
}
if config.SMTPConfig.Enabled {
if cfg.SMTPConfig.Enabled {
SMTP := new(smtpservice.SMTPservice)
SMTP.Setup(config)
SMTP.Setup(cfg)
comm.IComm = append(comm.IComm, SMTP)
}
if config.SlackConfig.Enabled {
if cfg.SlackConfig.Enabled {
Slack := new(slack.Slack)
Slack.Setup(config)
Slack.Setup(cfg)
comm.IComm = append(comm.IComm, Slack)
}

View File

@@ -7,19 +7,19 @@ import (
)
func TestNewComm(t *testing.T) {
var config config.CommunicationsConfig
communications := NewComm(config)
var cfg config.CommunicationsConfig
communications := NewComm(&cfg)
if len(communications.IComm) != 0 {
t.Errorf("Test failed, communications NewComm, expected len 0, got len %d",
len(communications.IComm))
}
config.TelegramConfig.Enabled = true
config.SMSGlobalConfig.Enabled = true
config.SMTPConfig.Enabled = true
config.SlackConfig.Enabled = true
communications = NewComm(config)
cfg.TelegramConfig.Enabled = true
cfg.SMSGlobalConfig.Enabled = true
cfg.SMTPConfig.Enabled = true
cfg.SlackConfig.Enabled = true
communications = NewComm(&cfg)
if len(communications.IComm) != 4 {
t.Errorf("Test failed, communications NewComm, expected len 4, got len %d",

View File

@@ -59,12 +59,12 @@ type Slack struct {
// Setup takes in a slack configuration, sets bots target channel and
// sets verification token to access workspace
func (s *Slack) Setup(config config.CommunicationsConfig) {
s.Name = config.SlackConfig.Name
s.Enabled = config.SlackConfig.Enabled
s.Verbose = config.SlackConfig.Verbose
s.TargetChannel = config.SlackConfig.TargetChannel
s.VerificationToken = config.SlackConfig.VerificationToken
func (s *Slack) Setup(cfg *config.CommunicationsConfig) {
s.Name = cfg.SlackConfig.Name
s.Enabled = cfg.SlackConfig.Enabled
s.Verbose = cfg.SlackConfig.Verbose
s.TargetChannel = cfg.SlackConfig.TargetChannel
s.VerificationToken = cfg.SlackConfig.VerificationToken
}
// Connect connects to the service
@@ -92,9 +92,9 @@ func (s *Slack) GetChannelsString() []string {
}
// GetUsernameByID returns a users name by ID
func (s *Slack) GetUsernameByID(ID string) string {
func (s *Slack) GetUsernameByID(id string) string {
for i := range s.Details.Users {
if s.Details.Users[i].ID == ID {
if s.Details.Users[i].ID == id {
return s.Details.Users[i].Name
}
}
@@ -117,7 +117,7 @@ func (s *Slack) GetGroupIDByName(group string) (string, error) {
return s.Details.Groups[i].ID, nil
}
}
return "", errors.New("Channel not found")
return "", errors.New("channel not found")
}
// GetChannelIDByName returns a channel ID by its corresponding name
@@ -127,7 +127,7 @@ func (s *Slack) GetChannelIDByName(channel string) (string, error) {
return s.Details.Channels[i].ID, nil
}
}
return "", errors.New("Channel not found")
return "", errors.New("channel not found")
}
// GetUsersInGroup returns a list of users currently in a group
@@ -263,7 +263,7 @@ func (s *Slack) handlePresenceChange(resp []byte) error {
func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error {
if data.ReplyTo != 0 {
return fmt.Errorf("ReplyTo != 0")
return errors.New("reply to is != 0")
}
var msg Message
err := common.JSONDecode(resp, &msg)
@@ -276,7 +276,7 @@ func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error
msg.User, msg.Text)
}
if string(msg.Text[0]) == "!" {
return s.HandleMessage(msg)
return s.HandleMessage(&msg)
}
return nil
}
@@ -287,7 +287,7 @@ func (s *Slack) handleErrorResponse(data WebsocketResponse) error {
}
if s.WebsocketConn == nil {
return errors.New("Websocket connection is nil")
return errors.New("websocket connection is nil")
}
if err := s.WebsocketConn.Close(); err != nil {
@@ -298,7 +298,7 @@ func (s *Slack) handleErrorResponse(data WebsocketResponse) error {
s.Connected = false
return s.NewConnection()
}
return fmt.Errorf("Unknown error '%s'", data.Error.Msg)
return fmt.Errorf("unknown error '%s'", data.Error.Msg)
}
func (s *Slack) handleHelloResponse() {
@@ -352,13 +352,17 @@ func (s *Slack) WebsocketSend(eventType, text string) error {
return err
}
if s.WebsocketConn == nil {
return errors.New("Websocket not connected")
return errors.New("websocket not connected")
}
return s.WebsocketConn.WriteMessage(websocket.TextMessage, data)
}
// HandleMessage handles incoming messages and/or commands from slack
func (s *Slack) HandleMessage(msg Message) error {
func (s *Slack) HandleMessage(msg *Message) error {
if msg == nil {
return errors.New("msg is nil")
}
msg.Text = common.StringToLower(msg.Text)
switch {
case common.StringContains(msg.Text, cmdStatus):

View File

@@ -43,7 +43,8 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig(config.ConfigTestFile)
s.Setup(cfg.GetCommunicationsConfig())
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
s.Verbose = true
}
@@ -103,7 +104,7 @@ func TestGetChannelsString(t *testing.T) {
func TestGetUsernameByID(t *testing.T) {
username := s.GetUsernameByID("1337")
if len(username) != 0 {
if username != "" {
t.Error("test failed - slack GetUsernameByID() error")
}
@@ -144,7 +145,7 @@ func TestGetUsernameByID(t *testing.T) {
func TestGetIDByName(t *testing.T) {
id, err := s.GetIDByName("batman")
if err == nil || len(id) != 0 {
if err == nil || id != "" {
t.Error("test failed - slack GetIDByName() error")
}
@@ -161,7 +162,7 @@ func TestGetIDByName(t *testing.T) {
func TestGetGroupIDByName(t *testing.T) {
id, err := s.GetGroupIDByName("batman")
if err == nil || len(id) != 0 {
if err == nil || id != "" {
t.Error("test failed - slack GetGroupIDByName() error")
}
@@ -179,7 +180,7 @@ func TestGetGroupIDByName(t *testing.T) {
func TestGetChannelIDByName(t *testing.T) {
id, err := s.GetChannelIDByName("1337")
if err == nil || len(id) != 0 {
if err == nil || id != "" {
t.Error("test failed - slack GetChannelIDByName() error")
}
@@ -264,7 +265,7 @@ func TestHandleMessageResponse(t *testing.T) {
data.ReplyTo = 1
err := s.handleMessageResponse(nil, data)
if err.Error() != "ReplyTo != 0" {
if err.Error() != "reply to is != 0" {
t.Errorf("test failed - slack handleMessageResponse(), Incorrect Error: %s",
err)
}
@@ -341,7 +342,7 @@ func TestWebsocketSend(t *testing.T) {
}
func TestHandleMessage(t *testing.T) {
var msg Message
msg := &Message{}
err := s.HandleMessage(msg)
if err == nil {

View File

@@ -33,20 +33,20 @@ type SMSGlobal struct {
// Setup takes in a SMSGlobal configuration, sets username, password and
// and recipient list
func (s *SMSGlobal) Setup(config config.CommunicationsConfig) {
s.Name = config.SMSGlobalConfig.Name
s.Enabled = config.SMSGlobalConfig.Enabled
s.Verbose = config.SMSGlobalConfig.Verbose
s.Username = config.SMSGlobalConfig.Username
s.Password = config.SMSGlobalConfig.Password
func (s *SMSGlobal) Setup(cfg *config.CommunicationsConfig) {
s.Name = cfg.SMSGlobalConfig.Name
s.Enabled = cfg.SMSGlobalConfig.Enabled
s.Verbose = cfg.SMSGlobalConfig.Verbose
s.Username = cfg.SMSGlobalConfig.Username
s.Password = cfg.SMSGlobalConfig.Password
var contacts []Contact
for x := range config.SMSGlobalConfig.Contacts {
for x := range cfg.SMSGlobalConfig.Contacts {
contacts = append(contacts,
Contact{
Name: config.SMSGlobalConfig.Contacts[x].Name,
Number: config.SMSGlobalConfig.Contacts[x].Number,
Enabled: config.SMSGlobalConfig.Contacts[x].Enabled,
Name: cfg.SMSGlobalConfig.Contacts[x].Name,
Number: cfg.SMSGlobalConfig.Contacts[x].Number,
Enabled: cfg.SMSGlobalConfig.Contacts[x].Enabled,
},
)
}

View File

@@ -13,7 +13,8 @@ var s SMSGlobal
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
s.Setup(cfg.GetCommunicationsConfig())
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
}
func TestConnect(t *testing.T) {

View File

@@ -27,15 +27,15 @@ type SMTPservice struct {
// Setup takes in a SMTP configuration and sets SMTP server details and
// recipient list
func (s *SMTPservice) Setup(config config.CommunicationsConfig) {
s.Name = config.SMTPConfig.Name
s.Enabled = config.SMTPConfig.Enabled
s.Verbose = config.SMTPConfig.Verbose
s.Host = config.SMTPConfig.Host
s.Port = config.SMTPConfig.Port
s.AccountName = config.SMTPConfig.AccountName
s.AccountPassword = config.SMTPConfig.AccountPassword
s.RecipientList = config.SMTPConfig.RecipientList
func (s *SMTPservice) Setup(cfg *config.CommunicationsConfig) {
s.Name = cfg.SMTPConfig.Name
s.Enabled = cfg.SMTPConfig.Enabled
s.Verbose = cfg.SMTPConfig.Verbose
s.Host = cfg.SMTPConfig.Host
s.Port = cfg.SMTPConfig.Port
s.AccountName = cfg.SMTPConfig.AccountName
s.AccountPassword = cfg.SMTPConfig.AccountPassword
s.RecipientList = cfg.SMTPConfig.RecipientList
}
// Connect connects to service

View File

@@ -12,7 +12,8 @@ var s SMTPservice
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
s.Setup(cfg.GetCommunicationsConfig())
commsCfg := cfg.GetCommunicationsConfig()
s.Setup(&commsCfg)
}
func TestConnect(t *testing.T) {

View File

@@ -52,11 +52,11 @@ type Telegram struct {
}
// Setup takes in a Telegram configuration and sets verification token
func (t *Telegram) Setup(config config.CommunicationsConfig) {
t.Name = config.TelegramConfig.Name
t.Enabled = config.TelegramConfig.Enabled
t.Token = config.TelegramConfig.VerificationToken
t.Verbose = config.TelegramConfig.Verbose
func (t *Telegram) Setup(cfg *config.CommunicationsConfig) {
t.Name = cfg.TelegramConfig.Name
t.Enabled = cfg.TelegramConfig.Enabled
t.Token = cfg.TelegramConfig.VerificationToken
t.Verbose = cfg.TelegramConfig.Verbose
}
// Connect starts an initial connection

View File

@@ -7,12 +7,17 @@ import (
"github.com/thrasher-/gocryptotrader/config"
)
const (
testErrNotFound = "Not Found"
)
var T Telegram
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
T.Setup(cfg.GetCommunicationsConfig())
commsCfg := cfg.GetCommunicationsConfig()
T.Setup(&commsCfg)
if T.Name != "Telegram" || T.Enabled ||
T.Token != "testest" || T.Verbose {
t.Error("test failed - telegram Setup() error, unexpected setup values",
@@ -34,7 +39,7 @@ func TestPushEvent(t *testing.T) {
}
T.AuthorisedClients = append(T.AuthorisedClients, 1337)
err = T.PushEvent(base.Event{})
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram PushEvent() error, expected 'Not found' got '%s'",
err)
}
@@ -44,42 +49,42 @@ func TestHandleMessages(t *testing.T) {
t.Parallel()
chatID := int64(1337)
err := T.HandleMessages(cmdHelp, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages(cmdStart, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages(cmdOrders, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages(cmdStatus, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages(cmdTicker, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages(cmdSettings, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages(cmdPortfolio, chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
err = T.HandleMessages("Not a command", chatID)
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram HandleMessages() error, expected 'Not found' got '%s'",
err)
}
@@ -96,7 +101,7 @@ func TestGetUpdates(t *testing.T) {
func TestTestConnection(t *testing.T) {
t.Parallel()
err := T.TestConnection()
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram TestConnection() error, expected 'Not found' got '%s'",
err)
}
@@ -105,7 +110,7 @@ func TestTestConnection(t *testing.T) {
func TestSendMessage(t *testing.T) {
t.Parallel()
err := T.SendMessage("Test message", int64(1337))
if err.Error() != "Not Found" {
if err.Error() != testErrNotFound {
t.Errorf("test failed - telegram SendMessage() error, expected 'Not found' got '%s'",
err)
}