mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
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:
@@ -264,22 +264,19 @@ func ExtractPort(host string) int {
|
||||
|
||||
// OutputCSV dumps data into a file as comma-separated values
|
||||
func OutputCSV(filePath string, data [][]string) error {
|
||||
_, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
errTwo := ioutil.WriteFile(filePath, nil, 0770)
|
||||
if errTwo != nil {
|
||||
return errTwo
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
writer := csv.NewWriter(file)
|
||||
return writer.WriteAll(data)
|
||||
if err = writer.WriteAll(data); err != nil {
|
||||
file.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
file.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetURIPath returns the path of a URL given a URI
|
||||
|
||||
@@ -2,9 +2,9 @@ package crypto
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/md5" // nolint:gosec
|
||||
"crypto/md5" // nolint // Used by some exchanges
|
||||
"crypto/rand"
|
||||
"crypto/sha1" // nolint:gosec
|
||||
"crypto/sha1" // nolint // Used by some exchanges
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
@@ -62,7 +62,7 @@ func GetRandomSalt(input []byte, saltLen int) ([]byte, error) {
|
||||
|
||||
// GetMD5 returns a MD5 hash of a byte array
|
||||
func GetMD5(input []byte) []byte {
|
||||
m := md5.New() // nolint:gosec
|
||||
m := md5.New() // nolint // Used by some exchanges
|
||||
m.Write(input)
|
||||
return m.Sum(nil)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func GetHMAC(hashType int, input, key []byte) []byte {
|
||||
// Sha1ToHex takes a string, sha1 hashes it and return a hex string of the
|
||||
// result
|
||||
func Sha1ToHex(data string) string {
|
||||
h := sha1.New() // nolint:gosec
|
||||
h := sha1.New() // nolint // Used by some exchanges
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
@@ -32,8 +32,9 @@ func UnZip(src, dest string) (fileList []string, err error) {
|
||||
}
|
||||
|
||||
for x := range z.File {
|
||||
fPath := filepath.Join(dest, z.File[x].Name) // nolint:gosec
|
||||
// We ignore gosec linter above because the code below files the file traversal bug when extracting archives
|
||||
fPath := filepath.Join(dest, z.File[x].Name) // nolint // We ignore
|
||||
// gosec linter above because the code below files the file traversal
|
||||
// bug when extracting archives
|
||||
if !strings.HasPrefix(fPath, filepath.Clean(dest)+string(os.PathSeparator)) {
|
||||
err = z.Close()
|
||||
if err != nil {
|
||||
@@ -116,13 +117,12 @@ func Zip(src, dest string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
z := zip.NewWriter(f)
|
||||
defer z.Close()
|
||||
|
||||
err = addFilesToZip(z, src, i.IsDir())
|
||||
if err != nil {
|
||||
z.Close()
|
||||
errCls := f.Close()
|
||||
if errCls != nil {
|
||||
log.Errorf(log.Global, "Failed to close file handle, manual deletion required: %v", errCls)
|
||||
@@ -134,6 +134,9 @@ func Zip(src, dest string) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
z.Close()
|
||||
f.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,9 @@ func (t *TimedMutex) stopTimer() bool {
|
||||
// isTimerNil safely read locks to detect nil
|
||||
func (t *TimedMutex) isTimerNil() bool {
|
||||
t.timerLock.RLock()
|
||||
defer t.timerLock.RUnlock()
|
||||
return t.timer == nil
|
||||
isNil := t.timer == nil
|
||||
t.timerLock.RUnlock()
|
||||
return isNil
|
||||
}
|
||||
|
||||
// setTimer safely locks and sets a timer
|
||||
|
||||
Reference in New Issue
Block a user