Skip to content

Commit

Permalink
Optimisation: Large struct pointer conversion (final part) (thrasher-…
Browse files Browse the repository at this point in the history
…corp#265)

Completes large struct pointer optomisations over the entire codebase and enables hugeParams linter by default
  • Loading branch information
xtda authored and thrasher- committed Apr 4, 2019
1 parent 107cf76 commit ca55f2f
Show file tree
Hide file tree
Showing 97 changed files with 195 additions and 195 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ linters-settings:
- experimental
disabled-checks:
- wrapperFunc
- hugeParam
- importShadow
- rangeValCopy
- methodExprCall
Expand Down
2 changes: 1 addition & 1 deletion currency/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func GetTotalMarketCryptocurrencies() ([]Code, error) {
}

// RunStorageUpdater runs a new foreign exchange updater instance
func RunStorageUpdater(o BotOverrides, m MainConfiguration, filepath string, v bool) error {
func RunStorageUpdater(o BotOverrides, m *MainConfiguration, filepath string, v bool) error {
return storage.RunUpdater(o, m, filepath, v)
}

Expand Down
2 changes: 1 addition & 1 deletion currency/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Storage) SetDefaults() {
// dump file and keep foreign exchange rates updated as fast as possible without
// triggering rate limiters, it will also run a full cryptocurrency check
// through coin market cap and expose analytics for exchange services
func (s *Storage) RunUpdater(overrides BotOverrides, settings MainConfiguration, filePath string, verbose bool) error {
func (s *Storage) RunUpdater(overrides BotOverrides, settings *MainConfiguration, filePath string, verbose bool) error {
s.mtx.Lock()

if !settings.Cryptocurrencies.HasData() {
Expand Down
7 changes: 4 additions & 3 deletions currency/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "testing"
func TestRunUpdater(t *testing.T) {
var newStorage Storage

err := newStorage.RunUpdater(BotOverrides{}, MainConfiguration{}, "", false)
emptyMainConfig := MainConfiguration{}
err := newStorage.RunUpdater(BotOverrides{}, &emptyMainConfig, "", false)
if err == nil {
t.Fatal("Test Failed storage RunUpdater() error cannot be nil")
}
Expand All @@ -15,12 +16,12 @@ func TestRunUpdater(t *testing.T) {
FiatDisplayCurrency: USD,
}

err = newStorage.RunUpdater(BotOverrides{}, mainConfig, "", false)
err = newStorage.RunUpdater(BotOverrides{}, &mainConfig, "", false)
if err == nil {
t.Fatal("Test Failed storage RunUpdater() error cannot be nil")
}

err = newStorage.RunUpdater(BotOverrides{}, mainConfig, "/bla", false)
err = newStorage.RunUpdater(BotOverrides{}, &mainConfig, "/bla", false)
if err != nil {
t.Fatal("Test Failed storage RunUpdater() error", err)
}
Expand Down
4 changes: 2 additions & 2 deletions exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func ReloadExchange(name string) error {
}

e := GetExchangeByName(nameLower)
e.Setup(exchCfg)
e.Setup(&exchCfg)
log.Debugf("%s exchange reloaded successfully.\n", name)
return nil
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func LoadExchange(name string, useWG bool, wg *sync.WaitGroup) error {
}

exchCfg.Enabled = true
exch.Setup(exchCfg)
exch.Setup(&exchCfg)

if useWG {
exch.Start(wg)
Expand Down
2 changes: 1 addition & 1 deletion exchanges/alphapoint/alphapoint_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (a *Alphapoint) UpdateTicker(p currency.Pair, assetType string) (ticker.Pri
tickerPrice.Volume = tick.Volume
tickerPrice.Last = tick.Last

err = ticker.ProcessTicker(a.GetName(), tickerPrice, assetType)
err = ticker.ProcessTicker(a.GetName(), &tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/anx/anx.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (a *ANX) SetDefaults() {
}

// Setup is run on startup to setup exchange with config values
func (a *ANX) Setup(exch config.ExchangeConfig) {
func (a *ANX) Setup(exch *config.ExchangeConfig) {
if !exch.Enabled {
a.SetEnabled(false)
} else {
Expand All @@ -102,7 +102,7 @@ func (a *ANX) Setup(exch config.ExchangeConfig) {
if err != nil {
log.Fatal(err)
}
err = a.SetAPIURL(&exch)
err = a.SetAPIURL(exch)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/anx/anx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestSetup(t *testing.T) {
if err != nil {
t.Error("Test Failed - ANX Setup() init error")
}
a.Setup(anxConfig)
a.Setup(&anxConfig)
a.APIKey = testAPIKey
a.APISecret = testAPISecret
a.AuthenticatedAPISupport = true
Expand Down
2 changes: 1 addition & 1 deletion exchanges/anx/anx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (a *ANX) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, err
tickerPrice.High = 0
}

err = ticker.ProcessTicker(a.GetName(), tickerPrice, assetType)
err = ticker.ProcessTicker(a.GetName(), &tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/binance/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (b *Binance) SetDefaults() {
}

// Setup takes in the supplied exchange configuration details and sets params
func (b *Binance) Setup(exch config.ExchangeConfig) {
func (b *Binance) Setup(exch *config.ExchangeConfig) {
if !exch.Enabled {
b.SetEnabled(false)
} else {
Expand All @@ -127,7 +127,7 @@ func (b *Binance) Setup(exch config.ExchangeConfig) {
if err != nil {
log.Fatal(err)
}
err = b.SetAPIURL(&exch)
err = b.SetAPIURL(exch)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestSetup(t *testing.T) {
binanceConfig.AuthenticatedAPISupport = true
binanceConfig.APIKey = testAPIKey
binanceConfig.APISecret = testAPISecret
b.Setup(binanceConfig)
b.Setup(&binanceConfig)
}

func TestGetExchangeValidCurrencyPairs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/binance/binance_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (b *Binance) UpdateTicker(p currency.Pair, assetType string) (ticker.Price,
tickerPrice.Last = tick[y].LastPrice
tickerPrice.Low = tick[y].LowPrice
tickerPrice.Volume = tick[y].Volume
ticker.ProcessTicker(b.Name, tickerPrice, assetType)
ticker.ProcessTicker(b.Name, &tickerPrice, assetType)
}
}
return ticker.GetTicker(b.Name, p, assetType)
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (b *Bitfinex) SetDefaults() {
}

// Setup takes in the supplied exchange configuration details and sets params
func (b *Bitfinex) Setup(exch config.ExchangeConfig) {
func (b *Bitfinex) Setup(exch *config.ExchangeConfig) {
if !exch.Enabled {
b.SetEnabled(false)
} else {
Expand All @@ -145,7 +145,7 @@ func (b *Bitfinex) Setup(exch config.ExchangeConfig) {
if err != nil {
log.Fatal(err)
}
err = b.SetAPIURL(&exch)
err = b.SetAPIURL(exch)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestSetup(t *testing.T) {
if err != nil {
t.Error("Test Failed - Bitfinex Setup() init error")
}
b.Setup(bfxConfig)
b.Setup(&bfxConfig)
b.APIKey = testAPIKey
b.APISecret = testAPISecret
if !b.Enabled || b.AuthenticatedAPISupport || b.RESTPollingDelay != time.Duration(10) ||
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitfinex/bitfinex_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (b *Bitfinex) UpdateTicker(p currency.Pair, assetType string) (ticker.Price
tick.Volume = tickerNew[x].Volume
tick.High = tickerNew[x].High

err = ticker.ProcessTicker(b.Name, tick, assetType)
err = ticker.ProcessTicker(b.Name, &tick, assetType)
if err != nil {
return tickerPrice, err
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bitflyer/bitflyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b *Bitflyer) SetDefaults() {
}

// Setup takes in the supplied exchange configuration details and sets params
func (b *Bitflyer) Setup(exch config.ExchangeConfig) {
func (b *Bitflyer) Setup(exch *config.ExchangeConfig) {
if !exch.Enabled {
b.SetEnabled(false)
} else {
Expand All @@ -130,7 +130,7 @@ func (b *Bitflyer) Setup(exch config.ExchangeConfig) {
if err != nil {
log.Fatal(err)
}
err = b.SetAPIURL(&exch)
err = b.SetAPIURL(exch)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitflyer/bitflyer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestSetup(t *testing.T) {
bitflyerConfig.APIKey = testAPIKey
bitflyerConfig.APISecret = testAPISecret

b.Setup(bitflyerConfig)
b.Setup(&bitflyerConfig)
}

func TestGetLatestBlockCA(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitflyer/bitflyer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (b *Bitflyer) UpdateTicker(p currency.Pair, assetType string) (ticker.Price
tickerPrice.Last = tickerNew.Last
tickerPrice.Volume = tickerNew.Volume
// tickerPrice.High
err = ticker.ProcessTicker(b.GetName(), tickerPrice, assetType)
err = ticker.ProcessTicker(b.GetName(), &tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bithumb/bithumb.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (b *Bithumb) SetDefaults() {
}

// Setup takes in the supplied exchange configuration details and sets params
func (b *Bithumb) Setup(exch config.ExchangeConfig) {
func (b *Bithumb) Setup(exch *config.ExchangeConfig) {
if !exch.Enabled {
b.SetEnabled(false)
} else {
Expand All @@ -112,7 +112,7 @@ func (b *Bithumb) Setup(exch config.ExchangeConfig) {
if err != nil {
log.Fatal(err)
}
err = b.SetAPIURL(&exch)
err = b.SetAPIURL(exch)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bithumb/bithumb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSetup(t *testing.T) {
bitConfig.APIKey = testAPIKey
bitConfig.APISecret = testAPISecret

b.Setup(bitConfig)
b.Setup(&bitConfig)
}

func TestGetTradablePairs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bithumb/bithumb_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (b *Bithumb) UpdateTicker(p currency.Pair, assetType string) (ticker.Price,
tp.Volume = tickers[currency].Volume1Day
tp.High = tickers[currency].MaxPrice

err = ticker.ProcessTicker(b.Name, tp, assetType)
err = ticker.ProcessTicker(b.Name, &tp, assetType)
if err != nil {
return tickerPrice, err
}
Expand Down
14 changes: 7 additions & 7 deletions exchanges/bitmex/bitmex.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (b *Bitmex) SetDefaults() {
}

// Setup takes in the supplied exchange configuration details and sets params
func (b *Bitmex) Setup(exch config.ExchangeConfig) {
func (b *Bitmex) Setup(exch *config.ExchangeConfig) {
if !exch.Enabled {
b.SetEnabled(false)
} else {
Expand All @@ -164,7 +164,7 @@ func (b *Bitmex) Setup(exch config.ExchangeConfig) {
if err != nil {
log.Fatal(err)
}
err = b.SetAPIURL(&exch)
err = b.SetAPIURL(exch)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (b *Bitmex) RemoveAPIKey(params APIKeyParams) (bool, error) {

return keyDeleted, b.SendAuthenticatedHTTPRequest(http.MethodDelete,
bitmexEndpointAPIkeys,
params,
&params,
&keyDeleted)
}

Expand All @@ -228,7 +228,7 @@ func (b *Bitmex) DisableAPIKey(params APIKeyParams) (APIKey, error) {

return keyInfo, b.SendAuthenticatedHTTPRequest(http.MethodPost,
bitmexEndpointDisableAPIkey,
params,
&params,
&keyInfo)
}

Expand All @@ -238,15 +238,15 @@ func (b *Bitmex) EnableAPIKey(params APIKeyParams) (APIKey, error) {

return keyInfo, b.SendAuthenticatedHTTPRequest(http.MethodPost,
bitmexEndpointEnableAPIkey,
params,
&params,
&keyInfo)
}

// GetTrollboxMessages returns messages from the bitmex trollbox
func (b *Bitmex) GetTrollboxMessages(params ChatGetParams) ([]Chat, error) {
var messages []Chat

return messages, b.SendHTTPRequest(bitmexEndpointTrollbox, params, &messages)
return messages, b.SendHTTPRequest(bitmexEndpointTrollbox, &params, &messages)
}

// SendTrollboxMessage sends a message to the bitmex trollbox
Expand All @@ -255,7 +255,7 @@ func (b *Bitmex) SendTrollboxMessage(params ChatSendParams) ([]Chat, error) {

return messages, b.SendAuthenticatedHTTPRequest(http.MethodPost,
bitmexEndpointTrollboxSend,
params,
&params,
&messages)
}

Expand Down
Loading

0 comments on commit ca55f2f

Please sign in to comment.