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

@@ -53,12 +53,11 @@ func GetHoldings(exch string) (Holdings, error) {
exch = strings.ToLower(exch)
service.Lock()
defer service.Unlock()
h, ok := service.accounts[exch]
if !ok {
service.Unlock()
return Holdings{}, errors.New("exchange account holdings not found")
}
defer service.Unlock()
return *h.h, nil
}

View File

@@ -17,7 +17,9 @@ func (a *Alphapoint) WebsocketClient() {
for a.Enabled {
var dialer websocket.Dialer
var err error
a.WebsocketConn, _, err = dialer.Dial(a.API.Endpoints.WebsocketURL, http.Header{})
var httpResp *http.Response
a.WebsocketConn, httpResp, err = dialer.Dial(a.API.Endpoints.WebsocketURL, http.Header{})
httpResp.Body.Close() // not used, so safely free the body
if err != nil {
log.Errorf(log.ExchangeSys, "%s Unable to connect to Websocket. Error: %s\n", a.Name, err)

View File

@@ -467,7 +467,7 @@ func (b *Bitmex) wsHandleData(respRaw []byte) error {
}
// ProcessOrderbook processes orderbook updates
func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPair currency.Pair, assetType asset.Item) error { // nolint: unparam
func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPair currency.Pair, assetType asset.Item) error {
if len(data) < 1 {
return errors.New("bitmex_websocket.go error - no orderbook data")
}

View File

@@ -419,8 +419,9 @@ func getInternationalBankDepositFee(c currency.Code, amount float64) float64 {
// IsLoaded returns whether or not the instrument map has been seeded
func (i *instrumentMap) IsLoaded() bool {
i.m.Lock()
defer i.m.Unlock()
return i.Loaded
isLoaded := i.Loaded
i.m.Unlock()
return isLoaded
}
// Seed seeds the instrument map

View File

@@ -20,7 +20,7 @@ import (
)
const (
warningBase64DecryptSecretKeyFailed = "exchange %s unable to base64 decode secret key.. Disabling Authenticated API support" // nolint:gosec
warningBase64DecryptSecretKeyFailed = "exchange %s unable to base64 decode secret key.. Disabling Authenticated API support" // nolint // False positive (G101: Potential hardcoded credentials)
// WarningAuthenticatedRequestWithoutCredentialsSet error message for authenticated request without credentials set
WarningAuthenticatedRequestWithoutCredentialsSet = "exchange %s authenticated HTTP request called but not supported due to unset/default API keys"
// DefaultHTTPTimeout is the default HTTP/HTTPS Timeout for exchange requests

View File

@@ -50,7 +50,7 @@ type AccountInfo struct {
Profile struct {
Email string `json:"email"`
UID string `json:"uid"`
BTCDepositAddress string `json:"btc_deposit_addres"` // nolint: misspell
BTCDepositAddress string `json:"btc_deposit_addres"` // nolint // API misspelling
} `json:"profile"`
}

View File

@@ -257,8 +257,9 @@ func (w *Websocket) setConnectedStatus(b bool) {
// IsConnected returns status of connection
func (w *Websocket) IsConnected() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.connected
isConnected := w.connected
w.connectionMutex.RUnlock()
return isConnected
}
func (w *Websocket) setConnectingStatus(b bool) {
@@ -270,8 +271,9 @@ func (w *Websocket) setConnectingStatus(b bool) {
// IsConnecting returns status of connecting
func (w *Websocket) IsConnecting() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.connecting
isConnecting := w.connecting
w.connectionMutex.RUnlock()
return isConnecting
}
func (w *Websocket) setEnabled(b bool) {
@@ -283,8 +285,9 @@ func (w *Websocket) setEnabled(b bool) {
// IsEnabled returns status of enabled
func (w *Websocket) IsEnabled() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.enabled
isEnabled := w.enabled
w.connectionMutex.RUnlock()
return isEnabled
}
func (w *Websocket) setInit(b bool) {
@@ -296,8 +299,9 @@ func (w *Websocket) setInit(b bool) {
// IsInit returns status of init
func (w *Websocket) IsInit() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.init
isInit := w.init
w.connectionMutex.RUnlock()
return isInit
}
func (w *Websocket) setTrafficMonitorRunning(b bool) {
@@ -309,8 +313,9 @@ func (w *Websocket) setTrafficMonitorRunning(b bool) {
// IsTrafficMonitorRunning returns status of the traffic monitor
func (w *Websocket) IsTrafficMonitorRunning() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.trafficMonitorRunning
trafficMonRunning := w.trafficMonitorRunning
w.connectionMutex.RUnlock()
return trafficMonRunning
}
func (w *Websocket) setConnectionMonitorRunning(b bool) {
@@ -322,8 +327,9 @@ func (w *Websocket) setConnectionMonitorRunning(b bool) {
// IsConnectionMonitorRunning returns status of connection monitor
func (w *Websocket) IsConnectionMonitorRunning() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.connectionMonitorRunning
isConnMonRunning := w.connectionMonitorRunning
w.connectionMutex.RUnlock()
return isConnMonRunning
}
// CanUseAuthenticatedWebsocketForWrapper Handles a common check to
@@ -616,8 +622,9 @@ func (w *Websocket) SetCanUseAuthenticatedEndpoints(val bool) {
// a thread safe manner
func (w *Websocket) CanUseAuthenticatedEndpoints() bool {
w.subscriptionMutex.Lock()
defer w.subscriptionMutex.Unlock()
return w.canUseAuthenticatedEndpoints
canUseAuthEndpoints := w.canUseAuthenticatedEndpoints
w.subscriptionMutex.Unlock()
return canUseAuthEndpoints
}
// SetResponseIDAndData adds data to IDResponses with locks and a nil check
@@ -642,6 +649,9 @@ func (w *WebsocketConnection) Dial(dialer *websocket.Dialer, headers http.Header
var err error
var conStatus *http.Response
w.Connection, conStatus, err = dialer.Dial(w.URL, headers)
if conStatus != nil {
conStatus.Body.Close()
}
if err != nil {
if conStatus != nil {
return fmt.Errorf("%v %v %v Error: %v", w.URL, conStatus, conStatus.StatusCode, err)
@@ -801,8 +811,9 @@ func (w *WebsocketConnection) setConnectedStatus(b bool) {
// IsConnected exposes websocket connection status
func (w *WebsocketConnection) IsConnected() bool {
w.connectionMutex.RLock()
defer w.connectionMutex.RUnlock()
return w.connected
isConnected := w.connected
w.connectionMutex.RUnlock()
return isConnected
}
// ReadMessage reads messages, can handle text, gzip and binary

View File

@@ -177,6 +177,7 @@ type WebsocketPingHandler struct {
Delay time.Duration
}
// UnhandledMessageWarning is used for unhandled websocket messages
type UnhandledMessageWarning struct {
Message string
}

View File

@@ -259,8 +259,9 @@ func (w *WebsocketOrderbookLocal) LoadSnapshot(newOrderbook *orderbook.Base) err
// calculation and cause problems
func (w *WebsocketOrderbookLocal) GetOrderbook(p currency.Pair, a asset.Item) *orderbook.Base {
w.m.Lock()
defer w.m.Unlock()
return w.ob[p][a]
ob := w.ob[p][a]
w.m.Unlock()
return ob
}
// FlushCache flushes w.ob data to be garbage collected and refreshed when a