Skip to content

Commit

Permalink
Linter fixes (#246)
Browse files Browse the repository at this point in the history
Linter fixes
  • Loading branch information
thrasher- committed Feb 5, 2019
1 parent d7368c1 commit 5e5ca8a
Show file tree
Hide file tree
Showing 85 changed files with 641 additions and 794 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Block style example:
func SendHTTPRequest(method, path string, headers map[string]string, body io.Reader) (string, error) {
result := strings.ToUpper(method)

if result != "POST" && result != "GET" && result != "DELETE" {
if result != http.MethodPost && result != http.MethodGet && result != http.MethodDelete {
return "", errors.New("Invalid HTTP method specified.")
}

Expand Down
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Block style example:
func SendHTTPRequest(method, path string, headers map[string]string, body io.Reader) (string, error) {
result := strings.ToUpper(method)

if result != "POST" && result != "GET" && result != "DELETE" {
if result != http.MethodPost && result != http.MethodGet && result != http.MethodDelete {
return "", errors.New("Invalid HTTP method specified.")
}

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ LINTOPTS += \
endif
LINTOPTS += \
--deadline=5m ./... | \
grep -v 'ALL_CAPS\|OP_' 2>&1 | \
tee /dev/stderr

get:
Expand Down
14 changes: 3 additions & 11 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func CalculateNetProfit(amount, priceThen, priceNow, costs float64) float64 {
func SendHTTPRequest(method, path string, headers map[string]string, body io.Reader) (string, error) {
result := strings.ToUpper(method)

if result != "POST" && result != "GET" && result != "DELETE" {
if result != http.MethodPost && result != http.MethodGet && result != http.MethodDelete {
return "", errors.New("invalid HTTP method specified")
}

Expand Down Expand Up @@ -509,20 +509,12 @@ func UnixTimestampStrToTime(timeStr string) (time.Time, error) {

// ReadFile reads a file and returns read data as byte array.
func ReadFile(path string) ([]byte, error) {
file, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return file, nil
return ioutil.ReadFile(path)
}

// WriteFile writes selected data to a file and returns an error
func WriteFile(file string, data []byte) error {
err := ioutil.WriteFile(file, data, 0644)
if err != nil {
return err
}
return nil
return ioutil.WriteFile(file, data, 0644)
}

// RemoveFile removes a file
Expand Down
2 changes: 1 addition & 1 deletion communications/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestGetChannelsString(t *testing.T) {
testpassed = true
}
}
if testpassed == false {
if !testpassed {
t.Error("test failed - slack GetChannelsString() error")
}
}
Expand Down
3 changes: 2 additions & 1 deletion communications/smsglobal/smsglobal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package smsglobal
import (
"errors"
"flag"
"net/http"
"net/url"
"strings"

Expand Down Expand Up @@ -164,7 +165,7 @@ func (s *SMSGlobal) SendMessage(to, message string) error {
headers := make(map[string]string)
headers["Content-Type"] = "application/x-www-form-urlencoded"

resp, err := common.SendHTTPRequest("POST",
resp, err := common.SendHTTPRequest(http.MethodPost,
smsGlobalAPIURL,
headers,
strings.NewReader(values.Encode()))
Expand Down
3 changes: 2 additions & 1 deletion communications/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"errors"
"fmt"
"net/http"

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/communications/base"
Expand Down Expand Up @@ -221,7 +222,7 @@ func (t *Telegram) SendHTTPRequest(path string, json []byte, result interface{})
headers := make(map[string]string)
headers["content-type"] = "application/json"

resp, err := common.SendHTTPRequest("POST", path, headers, bytes.NewBuffer(json))
resp, err := common.SendHTTPRequest(http.MethodPost, path, headers, bytes.NewBuffer(json))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions communications/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
T.Setup(cfg.GetCommunicationsConfig())
if T.Name != "Telegram" || T.Enabled != false ||
T.Token != "testest" || T.Verbose != false {
if T.Name != "Telegram" || T.Enabled ||
T.Token != "testest" || T.Verbose {
t.Error("test failed - telegram Setup() error, unexpected setup values",
T.Name, T.Enabled, T.Token, T.Verbose)
}
Expand Down
21 changes: 3 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,12 +1244,7 @@ func (c *Config) SaveConfig(configPath string) error {
return err
}
}

err = common.WriteFile(defaultPath, payload)
if err != nil {
return err
}
return nil
return common.WriteFile(defaultPath, payload)
}

// CheckConfig checks all config settings
Expand Down Expand Up @@ -1279,12 +1274,7 @@ func (c *Config) CheckConfig() error {
c.GlobalHTTPTimeout = configDefaultHTTPTimeout
}

err = c.CheckClientBankAccounts()
if err != nil {
return err
}

return nil
return c.CheckClientBankAccounts()
}

// LoadConfig loads your configuration file into your configuration object
Expand Down Expand Up @@ -1318,12 +1308,7 @@ func (c *Config) UpdateConfig(configPath string, newCfg Config) error {
return err
}

err = c.LoadConfig(configPath)
if err != nil {
return err
}

return nil
return c.LoadConfig(configPath)
}

// GetConfig returns a pointer to a configuration object
Expand Down
6 changes: 1 addition & 5 deletions config/config_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ func PromptForConfigKey(initialSetup bool) ([]byte, error) {
log.Println("Please enter in your password: ")
pwPrompt := func(i *[]byte) error {
_, err := fmt.Scanln(i)
if err != nil {
return err
}

return nil
return err
}

var p1 []byte
Expand Down
6 changes: 3 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestUpdateExchangeBankAccounts(t *testing.T) {
var count int
for _, exch := range cfg.Exchanges {
if exch.Name == "Bitfinex" {
if exch.BankAccounts[0].Enabled == false {
if !exch.BankAccounts[0].Enabled {
count++
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestUpdateClientBankAccounts(t *testing.T) {
var count int
for _, bank := range cfg.BankAccounts {
if bank.BankName == b.BankName {
if bank.Enabled == false {
if !bank.Enabled {
count++
}
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestGetRequestCurrencyPairFormat(t *testing.T) {
)
}

exchFmt, err := cfg.GetRequestCurrencyPairFormat("Bitfinex")
exchFmt, err := cfg.GetRequestCurrencyPairFormat("Yobit")
if exchFmt.Uppercase || exchFmt.Delimiter != "_" || exchFmt.Separator != "-" {
t.Errorf(
"Test failed. TestGetRequestCurrencyPairFormat. Invalid values",
Expand Down
35 changes: 18 additions & 17 deletions currency/coinmarketcap/coinmarketcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -117,7 +118,7 @@ func (c *Coinmarketcap) GetCryptocurrencyInfo(currencyID ...int64) (CryptoCurren
val := url.Values{}
val.Set("id", strings.Join(currStr, ","))

err = c.SendHTTPRequest("GET", endpointCryptocurrencyInfo, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyInfo, val, &resp)
if err != nil {
return resp.Data, err
}
Expand All @@ -142,7 +143,7 @@ func (c *Coinmarketcap) GetCryptocurrencyIDMap() ([]CryptoCurrencyMap, error) {
return resp.Data, err
}

err = c.SendHTTPRequest("GET", endpointCryptocurrencyMap, nil, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyMap, nil, &resp)
if err != nil {
return resp.Data, err
}
Expand All @@ -169,7 +170,7 @@ func (c *Coinmarketcap) GetCryptocurrencyHistoricalListings() ([]CryptocurrencyH
// return resp.Data, err
// }

// err = c.SendHTTPRequest("GET", endpointCryptocurrencyHistoricalListings, nil, &resp)
// err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyHistoricalListings, nil, &resp)
// if err != nil {
// return resp.Data, err
// }
Expand Down Expand Up @@ -206,7 +207,7 @@ func (c *Coinmarketcap) GetCryptocurrencyLatestListing(start, limit int64) ([]Cr
val.Set("limit", strconv.FormatInt(limit, 10))
}

err = c.SendHTTPRequest("GET", endpointCryptocurrencyLatestListings, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyLatestListings, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -246,7 +247,7 @@ func (c *Coinmarketcap) GetCryptocurrencyLatestMarketPairs(currencyID, start, li
val.Set("limit", strconv.FormatInt(limit, 10))
}

err = c.SendHTTPRequest("GET", endpointCryptocurrencyMarketPairs, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointCryptocurrencyMarketPairs, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -284,7 +285,7 @@ func (c *Coinmarketcap) GetCryptocurrencyOHLCHistorical(currencyID int64, tStart
val.Set("time_end", strconv.FormatInt(tEnd.Unix(), 10))
}

err = c.SendHTTPRequest("GET", endpointOHLCVHistorical, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointOHLCVHistorical, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -318,7 +319,7 @@ func (c *Coinmarketcap) GetCryptocurrencyOHLCLatest(currencyID int64) (Cryptocur
val := url.Values{}
val.Set("id", strconv.FormatInt(currencyID, 10))

err = c.SendHTTPRequest("GET", endpointOHLCVLatest, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointOHLCVLatest, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -353,7 +354,7 @@ func (c *Coinmarketcap) GetCryptocurrencyLatestQuotes(currencyID ...int64) (Cryp
val := url.Values{}
val.Set("id", strings.Join(currStr, ","))

err = c.SendHTTPRequest("GET", endpointGetMarketQuotesLatest, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointGetMarketQuotesLatest, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -390,7 +391,7 @@ func (c *Coinmarketcap) GetCryptocurrencyHistoricalQuotes(currencyID int64, tSta
val.Set("time_end", strconv.FormatInt(tEnd.Unix(), 10))
}

err = c.SendHTTPRequest("GET", endpointGetMarketQuotesHistorical, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointGetMarketQuotesHistorical, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -425,7 +426,7 @@ func (c *Coinmarketcap) GetExchangeInfo(exchangeID ...int64) (ExchangeInfo, erro
val := url.Values{}
val.Set("id", strings.Join(exchStr, ","))

err = c.SendHTTPRequest("GET", endpointExchangeInfo, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointExchangeInfo, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -465,7 +466,7 @@ func (c *Coinmarketcap) GetExchangeMap(start, limit int64) ([]ExchangeMap, error
val.Set("limit", strconv.FormatInt(start, 10))
}

err = c.SendHTTPRequest("GET", endpointExchangeMap, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointExchangeMap, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -527,7 +528,7 @@ func (c *Coinmarketcap) GetExchangeLatestMarketPairs(exchangeID, start, limit in
val.Set("limit", strconv.FormatInt(start, 10))
}

err = c.SendHTTPRequest("GET", endpointExchangeMarketPairsLatest, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointExchangeMarketPairsLatest, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -562,7 +563,7 @@ func (c *Coinmarketcap) GetExchangeLatestQuotes(exchangeID ...int64) (ExchangeLa
val := url.Values{}
val.Set("id", strings.Join(exchStr, ","))

err = c.SendHTTPRequest("GET", endpointExchangeMarketQuoteLatest, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointExchangeMarketQuoteLatest, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -599,7 +600,7 @@ func (c *Coinmarketcap) GetExchangeHistoricalQuotes(exchangeID int64, tStart, tE
val.Set("time_end", strconv.FormatInt(tEnd.Unix(), 10))
}

err = c.SendHTTPRequest("GET", endpointExchangeMarketQuoteHistorical, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointExchangeMarketQuoteHistorical, val, &resp)
if err != nil {
return resp.Data, err
}
Expand All @@ -624,7 +625,7 @@ func (c *Coinmarketcap) GetGlobalMeticLatestQuotes() (GlobalMeticLatestQuotes, e
return resp.Data, err
}

err = c.SendHTTPRequest("GET", endpointGlobalQuoteLatest, nil, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointGlobalQuoteLatest, nil, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -659,7 +660,7 @@ func (c *Coinmarketcap) GetGlobalMeticHistoricalQuotes(tStart, tEnd time.Time) (
val.Set("time_end", strconv.FormatInt(tEnd.Unix(), 10))
}

err = c.SendHTTPRequest("GET", endpointGlobalQuoteHistorical, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointGlobalQuoteHistorical, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down Expand Up @@ -699,7 +700,7 @@ func (c *Coinmarketcap) GetPriceConversion(amount float64, currencyID int64, atH
val.Set("time", strconv.FormatInt(atHistoricTime.Unix(), 10))
}

err = c.SendHTTPRequest("GET", endpointPriceConversion, val, &resp)
err = c.SendHTTPRequest(http.MethodGet, endpointPriceConversion, val, &resp)
if err != nil {
return resp.Data, err
}
Expand Down
6 changes: 6 additions & 0 deletions currency/forexprovider/fixer.io/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ func (f *Fixer) GetLatestRates(base, symbols string) (map[string]float64, error)
// GetHistoricalRates returns historical exchange rate data for all available or
// a specific set of currencies.
// date - YYYY-MM-DD [required] A date in the past
// base - USD [optional]
// symbols - the desired symbols
func (f *Fixer) GetHistoricalRates(date, base string, symbols []string) (map[string]float64, error) {
var resp Rates

v := url.Values{}
v.Set("symbols", common.JoinStrings(symbols, ","))

if len(base) > 0 {
v.Set("base", base)
}

err := f.SendOpenHTTPRequest(date, v, &resp)
if err != nil {
return resp.Rates, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package openexchangerates
import (
"errors"
"fmt"
"net/http"
"net/url"
"strconv"

Expand Down Expand Up @@ -222,7 +223,7 @@ func (o *OXR) SendHTTPRequest(endpoint string, values url.Values, result interfa
headers["Authorization"] = "Token " + o.APIKey
path := APIURL + endpoint + "?" + values.Encode()

resp, err := common.SendHTTPRequest("GET", path, headers, nil)
resp, err := common.SendHTTPRequest(http.MethodGet, path, headers, nil)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 5e5ca8a

Please sign in to comment.