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

@@ -37,25 +37,20 @@ const (
// Constants here hold some messages
const (
ErrExchangeNameEmpty = "Exchange #%d in config: Exchange name is empty."
ErrExchangeAvailablePairsEmpty = "Exchange %s: Available pairs is empty."
ErrExchangeEnabledPairsEmpty = "Exchange %s: Enabled pairs is empty."
ErrExchangeBaseCurrenciesEmpty = "Exchange %s: Base currencies is empty."
ErrExchangeNotFound = "Exchange %s: Not found."
ErrNoEnabledExchanges = "No Exchanges enabled."
ErrCryptocurrenciesEmpty = "Cryptocurrencies variable is empty."
ErrFailureOpeningConfig = "Fatal error opening %s file. Error: %s"
ErrCheckingConfigValues = "Fatal error checking config values. Error: %s"
ErrSavingConfigBytesMismatch = "Config file %q bytes comparison doesn't match, read %s expected %s."
WarningSMSGlobalDefaultOrEmptyValues = "WARNING -- SMS Support disabled due to default or empty Username/Password values."
WarningSSMSGlobalSMSContactDefaultOrEmptyValues = "WARNING -- SMS contact #%d Name/Number disabled due to default or empty values."
WarningSSMSGlobalSMSNoContacts = "WARNING -- SMS Support disabled due to no enabled contacts."
WarningWebserverCredentialValuesEmpty = "WARNING -- Webserver support disabled due to empty Username/Password values."
WarningWebserverListenAddressInvalid = "WARNING -- Webserver support disabled due to invalid listen address."
WarningWebserverRootWebFolderNotFound = "WARNING -- Webserver support disabled due to missing web folder."
WarningExchangeAuthAPIDefaultOrEmptyValues = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values."
WarningCurrencyExchangeProvider = "WARNING -- Currency exchange provider invalid valid. Reset to Fixer."
WarningPairsLastUpdatedThresholdExceeded = "WARNING -- Exchange %s: Last manual update of available currency pairs has exceeded %d days. Manual update required!"
ErrExchangeNameEmpty = "exchange #%d name is empty"
ErrExchangeAvailablePairsEmpty = "exchange %s avaiable pairs is emtpy"
ErrExchangeEnabledPairsEmpty = "exchange %s enabled pairs is empty"
ErrExchangeBaseCurrenciesEmpty = "exchange %s base currencies is empty"
ErrExchangeNotFound = "exchange %s not found"
ErrNoEnabledExchanges = "no exchanges enabled"
ErrCryptocurrenciesEmpty = "cryptocurrencies variable is empty"
ErrFailureOpeningConfig = "fatal error opening %s file. Error: %s"
ErrCheckingConfigValues = "fatal error checking config values. Error: %s"
ErrSavingConfigBytesMismatch = "config file %q bytes comparison doesn't match, read %s expected %s"
WarningWebserverCredentialValuesEmpty = "webserver support disabled due to empty Username/Password values"
WarningWebserverListenAddressInvalid = "webserver support disabled due to invalid listen address"
WarningExchangeAuthAPIDefaultOrEmptyValues = "exchange %s authenticated API support disabled due to default/empty APIKey/Secret/ClientID values"
WarningPairsLastUpdatedThresholdExceeded = "exchange %s last manual update of available currency pairs has exceeded %d days. Manual update required!"
)
// Constants here define unset default values displayed in the config.json
@@ -257,20 +252,21 @@ func (c *Config) GetCurrencyConfig() CurrencyConfig {
// GetExchangeBankAccounts returns banking details associated with an exchange
// for depositing funds
func (c *Config) GetExchangeBankAccounts(exchangeName string, depositingCurrency string) (BankAccount, error) {
func (c *Config) GetExchangeBankAccounts(exchangeName, depositingCurrency string) (BankAccount, error) {
m.Lock()
defer m.Unlock()
for _, exch := range c.Exchanges {
if exch.Name == exchangeName {
for _, account := range exch.BankAccounts {
if common.StringContains(account.SupportedCurrencies, depositingCurrency) {
return account, nil
for x := range c.Exchanges {
if c.Exchanges[x].Name == exchangeName {
for y := range c.Exchanges[x].BankAccounts {
if common.StringContains(c.Exchanges[x].BankAccounts[y].SupportedCurrencies,
depositingCurrency) {
return c.Exchanges[x].BankAccounts[y], nil
}
}
}
}
return BankAccount{}, fmt.Errorf("Exchange %s bank details not found for %s",
return BankAccount{}, fmt.Errorf("exchange %s bank details not found for %s",
exchangeName,
depositingCurrency)
}
@@ -287,19 +283,21 @@ func (c *Config) UpdateExchangeBankAccounts(exchangeName string, bankCfg []BankA
return nil
}
}
return fmt.Errorf("UpdateExchangeBankAccounts() error exchange %s not found",
return fmt.Errorf("exchange %s not found",
exchangeName)
}
// GetClientBankAccounts returns banking details used for a given exchange
// and currency
func (c *Config) GetClientBankAccounts(exchangeName string, targetCurrency string) (BankAccount, error) {
func (c *Config) GetClientBankAccounts(exchangeName, targetCurrency string) (BankAccount, error) {
m.Lock()
defer m.Unlock()
for _, bank := range c.BankAccounts {
if (common.StringContains(bank.SupportedExchanges, exchangeName) || bank.SupportedExchanges == "ALL") && common.StringContains(bank.SupportedCurrencies, targetCurrency) {
return bank, nil
for x := range c.BankAccounts {
if (common.StringContains(c.BankAccounts[x].SupportedExchanges, exchangeName) ||
c.BankAccounts[x].SupportedExchanges == "ALL") &&
common.StringContains(c.BankAccounts[x].SupportedCurrencies, targetCurrency) {
return c.BankAccounts[x], nil
}
}
@@ -309,13 +307,13 @@ func (c *Config) GetClientBankAccounts(exchangeName string, targetCurrency strin
}
// UpdateClientBankAccounts updates the configuration for a bank
func (c *Config) UpdateClientBankAccounts(bankCfg BankAccount) error {
func (c *Config) UpdateClientBankAccounts(bankCfg *BankAccount) error {
m.Lock()
defer m.Unlock()
for i := range c.BankAccounts {
if c.BankAccounts[i].BankName == bankCfg.BankName && c.BankAccounts[i].AccountNumber == bankCfg.AccountNumber {
c.BankAccounts[i] = bankCfg
c.BankAccounts[i] = *bankCfg
return nil
}
}
@@ -378,9 +376,9 @@ func (c *Config) GetCommunicationsConfig() CommunicationsConfig {
// UpdateCommunicationsConfig sets a new updated version of a Communications
// configuration
func (c *Config) UpdateCommunicationsConfig(config CommunicationsConfig) {
func (c *Config) UpdateCommunicationsConfig(config *CommunicationsConfig) {
m.Lock()
c.Communications = config
c.Communications = *config
m.Unlock()
}
@@ -563,7 +561,7 @@ func (c *Config) CheckPairConsistency(exchName string) error {
exchCfg.EnabledPairs = common.JoinStrings(pair.PairsToStringArray(pairs), ",")
}
err = c.UpdateExchangeConfig(exchCfg)
err = c.UpdateExchangeConfig(&exchCfg)
if err != nil {
return err
}
@@ -710,12 +708,12 @@ func (c *Config) GetPrimaryForexProvider() string {
}
// UpdateExchangeConfig updates exchange configurations
func (c *Config) UpdateExchangeConfig(e ExchangeConfig) error {
func (c *Config) UpdateExchangeConfig(e *ExchangeConfig) error {
m.Lock()
defer m.Unlock()
for i := range c.Exchanges {
if c.Exchanges[i].Name == e.Name {
c.Exchanges[i] = e
c.Exchanges[i] = *e
return nil
}
}
@@ -769,11 +767,11 @@ func (c *Config) CheckExchangeConfigValues() error {
exch.APIKey == DefaultUnsetAPIKey ||
exch.APISecret == DefaultUnsetAPISecret {
c.Exchanges[i].AuthenticatedAPISupport = false
log.Warn(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
log.Warnf(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
} else if exch.Name == "ITBIT" || exch.Name == "Bitstamp" || exch.Name == "COINUT" || exch.Name == "CoinbasePro" {
if exch.ClientID == "" || exch.ClientID == "ClientID" {
c.Exchanges[i].AuthenticatedAPISupport = false
log.Warn(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
log.Warnf(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
}
}
}
@@ -798,27 +796,32 @@ func (c *Config) CheckExchangeConfigValues() error {
if len(exch.BankAccounts) == 0 {
c.Exchanges[i].BankAccounts = append(c.Exchanges[i].BankAccounts, BankAccount{})
} else {
for _, bankAccount := range exch.BankAccounts {
for y := range c.Exchanges[i].BankAccounts {
bankAccount := &c.Exchanges[i].BankAccounts[y]
if bankAccount.Enabled {
if bankAccount.BankName == "" || bankAccount.BankAddress == "" {
return fmt.Errorf("banking details for %s is enabled but variables not set",
log.Warnf("banking details for %s is enabled but variables not set",
exch.Name)
bankAccount.Enabled = false
}
if bankAccount.AccountName == "" || bankAccount.AccountNumber == "" {
return fmt.Errorf("banking account details for %s variables not set",
log.Warnf("banking account details for %s variables not set",
exch.Name)
bankAccount.Enabled = false
}
if bankAccount.SupportedCurrencies == "" {
return fmt.Errorf("banking account details for %s acceptable funding currencies not set",
log.Warnf("banking account details for %s acceptable funding currencies not set",
exch.Name)
bankAccount.Enabled = false
}
if bankAccount.BSBNumber == "" && bankAccount.IBAN == "" &&
bankAccount.SWIFTCode == "" {
return fmt.Errorf("banking account details for %s critical banking numbers not set",
log.Warnf("banking account details for %s critical banking numbers not set",
exch.Name)
bankAccount.Enabled = false
}
}
}
@@ -954,8 +957,8 @@ func (c *Config) CheckCurrencyConfigValues() error {
}
}
if len(c.Currency.Cryptocurrencies) == 0 {
if len(c.Cryptocurrencies) != 0 {
if c.Currency.Cryptocurrencies == "" {
if c.Cryptocurrencies != "" {
c.Currency.Cryptocurrencies = c.Cryptocurrencies
c.Cryptocurrencies = ""
} else {
@@ -1038,7 +1041,7 @@ func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error {
// CheckLoggerConfig checks to see logger values are present and valid in config
// if not creates a default instance of the logger
func (c *Config) CheckLoggerConfig() (err error) {
func (c *Config) CheckLoggerConfig() error {
m.Lock()
defer m.Unlock()
@@ -1065,13 +1068,13 @@ func (c *Config) CheckLoggerConfig() (err error) {
if len(c.Logging.File) > 0 {
logPath := path.Join(common.GetDefaultDataDir(runtime.GOOS), "logs")
err = common.CheckDir(logPath, true)
err := common.CheckDir(logPath, true)
if err != nil {
return
return err
}
log.LogPath = logPath
}
return
return nil
}
// GetFilePath returns the desired config file or the default config file name
@@ -1272,7 +1275,7 @@ func (c *Config) CheckConfig() error {
if c.Webserver.Enabled {
err = c.CheckWebserverConfigValues()
if err != nil {
log.Errorf(ErrCheckingConfigValues, err)
log.Warnf(ErrCheckingConfigValues, err)
c.Webserver.Enabled = false
}
}

View File

@@ -23,7 +23,7 @@ const (
// SaltRandomLength is the number of random bytes to append after the prefix string
SaltRandomLength = 12
errAESBlockSize = "The config file data is too small for the AES required block size"
errAESBlockSize = "config file data is too small for the AES required block size"
)
var (

View File

@@ -96,12 +96,12 @@ func TestUpdateClientBankAccounts(t *testing.T) {
t.Error("Test failed. UpdateClientBankAccounts LoadConfig error", err)
}
b := BankAccount{Enabled: false, BankName: "test", AccountNumber: "0234"}
err = cfg.UpdateClientBankAccounts(b)
err = cfg.UpdateClientBankAccounts(&b)
if err != nil {
t.Error("Test failed. UpdateClientBankAccounts error", err)
}
err = cfg.UpdateClientBankAccounts(BankAccount{})
err = cfg.UpdateClientBankAccounts(&BankAccount{})
if err == nil {
t.Error("Test failed. UpdateClientBankAccounts error")
}
@@ -181,7 +181,7 @@ func TestUpdateCommunicationsConfig(t *testing.T) {
if err != nil {
t.Error("Test failed. UpdateCommunicationsConfig LoadConfig error", err)
}
cfg.UpdateCommunicationsConfig(CommunicationsConfig{SlackConfig: SlackConfig{Name: "TEST"}})
cfg.UpdateCommunicationsConfig(&CommunicationsConfig{SlackConfig: SlackConfig{Name: "TEST"}})
if cfg.Communications.SlackConfig.Name != "TEST" {
t.Error("Test failed. UpdateCommunicationsConfig LoadConfig error")
}
@@ -327,7 +327,7 @@ func TestCheckPairConsistency(t *testing.T) {
}
tec.EnabledPairs = "DOGE_LTC,BTC_LTC"
err = cfg.UpdateExchangeConfig(tec)
err = cfg.UpdateExchangeConfig(&tec)
if err != nil {
t.Error("Test failed. CheckPairConsistency Update config failed, error:", err)
}
@@ -451,7 +451,7 @@ func TestGetDisabledExchanges(t *testing.T) {
}
exchCfg.Enabled = false
err = cfg.UpdateExchangeConfig(exchCfg)
err = cfg.UpdateExchangeConfig(&exchCfg)
if err != nil {
t.Errorf(
"Test failed. TestGetDisabledExchanges. UpdateExchangeConfig Error: %s", err.Error(),
@@ -495,6 +495,9 @@ func TestGetConfigCurrencyPairFormat(t *testing.T) {
}
exchFmt, err := cfg.GetConfigCurrencyPairFormat("Yobit")
if err != nil {
t.Errorf("Test failed. TestGetConfigCurrencyPairFormat err: %s", err)
}
if !exchFmt.Uppercase || exchFmt.Delimiter != "_" {
t.Errorf(
"Test failed. TestGetConfigCurrencyPairFormat. Invalid values",
@@ -519,6 +522,9 @@ func TestGetRequestCurrencyPairFormat(t *testing.T) {
}
exchFmt, err := cfg.GetRequestCurrencyPairFormat("Yobit")
if err != nil {
t.Errorf("Test failed. TestGetRequestCurrencyPairFormat. Err: %s", err)
}
if exchFmt.Uppercase || exchFmt.Delimiter != "_" || exchFmt.Separator != "-" {
t.Errorf(
"Test failed. TestGetRequestCurrencyPairFormat. Invalid values",
@@ -624,14 +630,14 @@ func TestUpdateExchangeConfig(t *testing.T) {
)
}
e.APIKey = "test1234"
err3 := UpdateExchangeConfig.UpdateExchangeConfig(e)
err3 := UpdateExchangeConfig.UpdateExchangeConfig(&e)
if err3 != nil {
t.Errorf(
"Test failed. UpdateExchangeConfig.UpdateExchangeConfig: %s", err.Error(),
)
}
e.Name = "testyTest"
err = UpdateExchangeConfig.UpdateExchangeConfig(e)
err = UpdateExchangeConfig.UpdateExchangeConfig(&e)
if err == nil {
t.Error("Test failed. UpdateExchangeConfig.UpdateExchangeConfig Error")
}
@@ -923,7 +929,7 @@ func TestUpdateConfig(t *testing.T) {
if err != nil {
t.Errorf("Test failed. %s", err)
}
if len(c.Currency.Cryptocurrencies) == 0 {
if c.Currency.Cryptocurrencies == "" {
t.Fatalf("Test failed. Cryptocurrencies should have been repopulated")
}
}