Bump golangci-lint to v1.24.0, linter fixes and general code improvements (#478)

* Bump golangci-lint version, update Go version deps and generic code improvements

* Fix wesbocket resp nil check and zip closures

* Update pprof path
This commit is contained in:
Adrian Gallagher
2020-04-09 13:07:32 +10:00
committed by GitHub
parent 4748a7849c
commit 0d787bc259
47 changed files with 193 additions and 178 deletions

View File

@@ -313,16 +313,11 @@ func checkMissingExchanges() []string {
// readFileData reads the file data from the given json file
func readFileData(fileName string) (Config, error) {
var c Config
file, err := os.Open(fileName)
data, err := ioutil.ReadFile(fileName)
if err != nil {
return c, err
}
defer file.Close()
byteValue, err := ioutil.ReadAll(file)
if err != nil {
return c, err
}
err = json.Unmarshal(byteValue, &c)
err = json.Unmarshal(data, &c)
if err != nil {
return c, err
}
@@ -609,6 +604,7 @@ func htmlScrapeDefault(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -664,6 +660,7 @@ func htmlScrapeBTSE(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -694,6 +691,7 @@ func htmlScrapeBitfinex(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
if err != nil {
return nil, err
@@ -727,6 +725,7 @@ func htmlScrapeBitmex(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -764,6 +763,7 @@ func htmlScrapeHitBTC(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
if err != nil {
return nil, err
@@ -798,6 +798,7 @@ func htmlScrapeBTCMarkets(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tempData, err := ioutil.ReadAll(temp.Body)
if err != nil {
return resp, err
@@ -819,6 +820,7 @@ func htmlScrapeBitflyer(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -870,6 +872,7 @@ func htmlScrapeOk(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -923,6 +926,7 @@ func htmlScrapeANX(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
if err != nil {
return nil, err
@@ -962,6 +966,7 @@ func htmlScrapeExmo(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer httpResp.Body.Close()
a, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return nil, err
@@ -982,6 +987,7 @@ func htmlScrapePoloniex(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -1034,6 +1040,7 @@ func htmlScrapeItBit(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -1067,6 +1074,7 @@ func htmlScrapeLakeBTC(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
if err != nil {
return nil, err
@@ -1088,6 +1096,7 @@ func htmlScrapeBitstamp(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
if err != nil {
return nil, err
@@ -1108,6 +1117,7 @@ func htmlScrapeKraken(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -1163,6 +1173,7 @@ func htmlScrapeAlphaPoint(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
loop:
for {
@@ -1217,6 +1228,7 @@ func htmlScrapeYobit(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return resp, err
}
defer temp.Body.Close()
tokenizer := html.NewTokenizer(temp.Body)
var case1, case2, case3 bool
loop:
@@ -1274,6 +1286,7 @@ func htmlScrapeLocalBitcoins(htmlData *HTMLScrapingData) ([]string, error) {
if err != nil {
return nil, err
}
defer temp.Body.Close()
a, err := ioutil.ReadAll(temp.Body)
if err != nil {
return nil, err

View File

@@ -43,14 +43,13 @@ func TestMain(m *testing.M) {
}
usageData = testConfigData
setTestVars()
defer os.Exit(m.Run())
defer func() {
err := removeTestFileVars()
if err != nil {
log.Error(log.Global, err)
os.Exit(1)
}
}()
testExitCode := m.Run()
err = removeTestFileVars()
if err != nil {
log.Error(log.Global, err)
os.Exit(1)
}
os.Exit(testExitCode)
}
func areTestAPIKeysSet() bool {

View File

@@ -18,7 +18,7 @@ import (
)
var (
dbConn *database.Db
dbConn *database.Instance
configFile string
defaultDataDir string
migrationDir string
@@ -26,7 +26,7 @@ var (
args string
)
func openDbConnection(driver string) (err error) {
func openDBConnection(driver string) (err error) {
if driver == database.DBPostgreSQL {
dbConn, err = dbPSQL.Connect()
if err != nil {
@@ -68,7 +68,7 @@ func main() {
os.Exit(1)
}
err = openDbConnection(conf.Database.Driver)
err = openDBConnection(conf.Database.Driver)
if err != nil {
fmt.Println(err)
os.Exit(1)

View File

@@ -14,6 +14,7 @@ import (
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/core"
)
@@ -267,50 +268,44 @@ func main() {
// GetConfiguration retrieves the documentation configuration
func GetConfiguration() (Config, error) {
var c Config
configFilePath := filepath.Join([]string{toolDir, "config.json"}...)
file, err := os.OpenFile(configFilePath, os.O_RDWR, os.ModePerm)
if err != nil {
fmt.Println("Creating configuration file, please check to add a different github repository path and change preferences")
configFilePath := filepath.Join(toolDir, "config.json")
file, err = os.Create(configFilePath)
if file.Exists(configFilePath) {
config, err := ioutil.ReadFile(configFilePath)
if err != nil {
return c, err
}
// Set default params for configuration
c.GithubRepo = DefaultRepo
c.ContributorFile = true
c.LicenseFile = true
c.RootReadme = true
c.Exclusions.Directories = DefaultExcludedDirectories
data, mErr := json.MarshalIndent(c, "", " ")
if mErr != nil {
return c, mErr
}
_, err = file.WriteAt(data, 0)
err = json.Unmarshal(config, &c)
if err != nil {
return c, err
}
if c.GithubRepo == "" {
return c, errors.New("repository not set in config.json file, please change")
}
return c, nil
}
defer file.Close()
fmt.Println("Creating configuration file, please check to add a different github repository path and change preferences")
config, err := ioutil.ReadAll(file)
// Set default params for configuration
c.GithubRepo = DefaultRepo
c.ContributorFile = true
c.LicenseFile = true
c.RootReadme = true
c.Exclusions.Directories = DefaultExcludedDirectories
data, err := json.MarshalIndent(c, "", " ")
if err != nil {
return c, err
}
err = json.Unmarshal(config, &c)
if err != nil {
if err := ioutil.WriteFile(configFilePath, data, 0770); err != nil {
return c, err
}
if c.GithubRepo == "" {
return c, errors.New("repository not set in config.json file, please change")
}
return c, nil
}

View File

@@ -735,12 +735,7 @@ func jsonifyInterface(params []interface{}) json.RawMessage {
func loadConfig() (Config, error) {
var config Config
file, err := os.OpenFile("wrapperconfig.json", os.O_RDONLY, os.ModePerm)
if err != nil {
return config, err
}
defer file.Close()
keys, err := ioutil.ReadAll(file)
keys, err := ioutil.ReadFile("wrapperconfig.json")
if err != nil {
return config, err
}
@@ -812,12 +807,11 @@ func outputToHTML(exchangeResponses []ExchangeResponses) {
return
}
defer file.Close()
err = tmpl.Execute(file, exchangeResponses)
if err != nil {
log.Print(err)
return
}
file.Close()
}
func outputToConsole(exchangeResponses []ExchangeResponses) {

View File

@@ -88,11 +88,13 @@ func main() {
log.Printf("Connecting to websocket host: %s", wsHost)
var dialer websocket.Dialer
WSConn, _, err = dialer.Dial(wsHost, http.Header{})
var resp *http.Response
WSConn, resp, err = dialer.Dial(wsHost, http.Header{})
if err != nil {
log.Println("Unable to connect to websocket server")
return
}
resp.Body.Close()
log.Println("Connected to websocket!")
log.Println("Authenticating..")