Skip to content

Commit

Permalink
chore: add ineffassign linter (#365)
Browse files Browse the repository at this point in the history
* add ineffassign linter

* remove ineff assign in test
  • Loading branch information
mga-chka authored Oct 5, 2023
1 parent 7013cd9 commit 5190ff0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ linters:
- govet
- nilerr
- wastedassign
- ineffassign
disable:
# Should be readded in the future with a dedicated PR to do the fix
- funlen
- gocognit
- gofumpt
- ifshort
- ineffassign
- nestif
- nolintlint
- revive
Expand Down
12 changes: 10 additions & 2 deletions cache/tmp_file_response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io/ioutil"
"net/http"
"os"

"github.com/contentsquare/chproxy/log"
)

// TmpFileResponseWriter caches Clickhouse response.
Expand Down Expand Up @@ -50,8 +52,14 @@ func (rw *TmpFileResponseWriter) Close() error {
func (rw *TmpFileResponseWriter) GetFile() (*os.File, error) {
if err := rw.bw.Flush(); err != nil {
fn := rw.tmpFile.Name()
err = rw.tmpFile.Close()
err = os.Remove(fn)
errTmp := rw.tmpFile.Close()
if errTmp != nil {
log.Errorf("cannot close tmpFile: %s, error: %s", fn, errTmp)
}
errTmp = os.Remove(fn)
if errTmp != nil {
log.Errorf("cannot remove tmpFile: %s, error: %s", fn, errTmp)
}
return nil, fmt.Errorf("cannot flush data into %q: %w", fn, err)
}

Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ func TestNewTLSConfig(t *testing.T) {
if err != nil {
panic(fmt.Sprintf("cannot build TLS config: %s", err))
}
tlsCfg, err = cfg.BuildTLSConfig(autocertManager)
tlsCfg, _ = cfg.BuildTLSConfig(autocertManager)
if tlsCfg.GetCertificate == nil {
t.Fatalf("expected func GetCertificate be set; got nil")
}
Expand Down
7 changes: 2 additions & 5 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,9 @@ func (c *cluster) getReplicaSticky(sessionId string) *replica {
r := c.replicas[idx]

for i := uint32(1); i < n; i++ {
tmpIdx := (idx + i) % n
// handling sticky session
sessionId := hash(sessionId)
tmpIdx = (sessionId) % n
tmpIdx := (sessionId) % n
tmpRSticky := c.replicas[tmpIdx]
log.Debugf("Sticky replica candidate is: %s", tmpRSticky.name)
if !tmpRSticky.isActive() {
Expand Down Expand Up @@ -907,11 +906,9 @@ func (r *replica) getHostSticky(sessionId string) *topology.Node {

// Scan all the hosts for the least loaded host.
for i := uint32(1); i < n; i++ {
tmpIdx := (idx + i) % n

// handling sticky session
sessionId := hash(sessionId)
tmpIdx = (sessionId) % n
tmpIdx := (sessionId) % n
tmpHSticky := r.hosts[tmpIdx]
log.Debugf("Sticky server candidate is: %s", tmpHSticky)
if !tmpHSticky.IsActive() {
Expand Down

0 comments on commit 5190ff0

Please sign in to comment.