Skip to content

Commit

Permalink
Bump golangci-lint to v1.24.0, linter fixes and general code improvem…
Browse files Browse the repository at this point in the history
…ents (thrasher-corp#478)

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

* Fix wesbocket resp nil check and zip closures

* Update pprof path
  • Loading branch information
thrasher- authored Apr 9, 2020
1 parent 4748a78 commit 0d787bc
Show file tree
Hide file tree
Showing 47 changed files with 193 additions and 178 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ environment:
PSQL_SSLMODE: disable
PSQL_SKIPSQLCMD: true
PSQL_TESTDBNAME: gct_dev_ci
stack: go 1.13.x
stack: go 1.14.x

services:
- postgresql96
Expand All @@ -49,7 +49,7 @@ before_test:

test_script:
# test back-end
- go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.20.1
- go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0
- '%GOPATH%\bin\golangci-lint.exe run --verbose'
- ps: >-
if($env:APPVEYOR_SCHEDULED_BUILD -eq 'true') {
Expand Down
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ linters:
# - varcheck

# disabled by default linters
# - bodyclose
- bodyclose
- depguard
- dogsled
# - dupl
Expand All @@ -38,13 +38,16 @@ linters:
- gofmt
- goimports
- golint
# - gomnd
- goprintffuncname
- gosec
# - interfacer
# - lll
# - maligned
- misspell
- nakedret
# - prealloc
- rowserrcheck
- scopelint
- stylecheck
- unconvert
Expand Down Expand Up @@ -80,5 +83,8 @@ issues:

exclude-rules:
- text: "weak cryptographic primitive"
linters:
- gosec
- text: "Expect WriteFile permissions to be 0600 or less"
linters:
- gosec
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ matrix:
dist: xenial
name: 'GoCryptoTrader [back-end] [linux] [64-bit]'
go:
- 1.13.x
- 1.14.x
env:
- GO111MODULE=on
- PSQL_USER=postgres
Expand All @@ -43,7 +43,7 @@ matrix:
dist: xenial
name: 'GoCryptoTrader [back-end] [linux] [32-bit]'
go:
- 1.13.x
- 1.14.x
env:
- GO111MODULE=on
- NO_RACE_TEST=1
Expand Down Expand Up @@ -72,7 +72,7 @@ matrix:
os: osx
name: 'GoCryptoTrader [back-end] [darwin]'
go:
- 1.13.x
- 1.14.x
env:
- GO111MODULE=on
- PSQL_USER=postgres
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13 as build
FROM golang:1.14 as build
WORKDIR /go/src/github.com/thrasher-corp/gocryptotrader
COPY . .
RUN GO111MODULE=on go mod vendor
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LDFLAGS = -ldflags "-w -s"
GCTPKG = github.com/thrasher-corp/gocryptotrader
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.20.1
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand Down
27 changes: 20 additions & 7 deletions cmd/apichecker/apicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions cmd/apichecker/apicheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/dbmigrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
)

var (
dbConn *database.Db
dbConn *database.Instance
configFile string
defaultDataDir string
migrationDir string
command string
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 {
Expand Down Expand Up @@ -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)
Expand Down
47 changes: 21 additions & 26 deletions cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -267,48 +268,42 @@ 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
}
}

defer file.Close()
if c.GithubRepo == "" {
return c, errors.New("repository not set in config.json file, please change")
}

config, err := ioutil.ReadAll(file)
if err != nil {
return c, err
return c, nil
}

err = json.Unmarshal(config, &c)
fmt.Println("Creating configuration file, please check to add a different github repository path and change preferences")

// 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
}

if c.GithubRepo == "" {
return c, errors.New("repository not set in config.json file, please change")
if err := ioutil.WriteFile(configFilePath, data, 0770); err != nil {
return c, err
}

return c, nil
Expand Down
Loading

0 comments on commit 0d787bc

Please sign in to comment.