summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-06-18 12:19:03 +0300
committerPaul Buetow <paul@buetow.org>2023-06-18 12:19:03 +0300
commite3c903c49c798531124a1c59859f47d04d4534b9 (patch)
tree641b0df3c3ed06c844e8bda48bc6b386d68e8e1f
parent6fe2579b65eaf78573d8b08c94dc1b313c20b9d9 (diff)
fix lint errors
-rw-r--r--Taskfile.yml13
-rw-r--r--cmd/gorum/main.go2
-rw-r--r--internal/client/tcpclient.go4
-rw-r--r--internal/config/config.go4
-rw-r--r--internal/quorum/quorum.go2
-rw-r--r--internal/server/tcpserver.go4
6 files changed, 21 insertions, 8 deletions
diff --git a/Taskfile.yml b/Taskfile.yml
index 3d16722..48f0e5c 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -4,10 +4,21 @@ tasks:
build:
cmds:
- go build -o gorum cmd/gorum/main.go
- race:
+ dev:
+ deps: ["vet", "lint"]
cmds:
- go build -race -o gorum cmd/gorum/main.go
test:
+ deps: ["vet", "lint"]
cmds:
- go clean -testcache
- go test ./... -v -race
+ vet:
+ cmds:
+ - go vet **/*.go
+ lint:
+ cmds:
+ - golangci-lint run
+ lint-install:
+ cmds:
+ - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
diff --git a/cmd/gorum/main.go b/cmd/gorum/main.go
index 5c4a116..72b0470 100644
--- a/cmd/gorum/main.go
+++ b/cmd/gorum/main.go
@@ -41,7 +41,7 @@ func contextWithSignal() (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(context.Background())
go func() {
- ch := make(chan os.Signal)
+ ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
<-ch
cancel()
diff --git a/internal/client/tcpclient.go b/internal/client/tcpclient.go
index f521ee3..1a76ad6 100644
--- a/internal/client/tcpclient.go
+++ b/internal/client/tcpclient.go
@@ -3,7 +3,7 @@ package client
import (
"context"
"fmt"
- "io/ioutil"
+ "io"
"log"
"net"
@@ -36,7 +36,7 @@ func tcpClientRun(ctx context.Context, node string, ch <-chan vote.Vote) error {
return err
}
- response, err := ioutil.ReadAll(conn)
+ response, err := io.ReadAll(conn)
if err != nil {
return err
}
diff --git a/internal/config/config.go b/internal/config/config.go
index 90435e5..fe23cbc 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -3,7 +3,7 @@ package config
import (
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"log"
"net"
"os"
@@ -27,7 +27,7 @@ func New(configFile string) (Config, error) {
}
defer file.Close()
- bytes, err := ioutil.ReadAll(file)
+ bytes, err := io.ReadAll(file)
if err != nil {
return c, err
}
diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go
index dfeabe6..20fbe8a 100644
--- a/internal/quorum/quorum.go
+++ b/internal/quorum/quorum.go
@@ -85,7 +85,7 @@ func (quo Quorum) score() (scores []Score) {
continue
}
for _, id := range vote.IDs {
- score, _ := scoreMap[id]
+ score := scoreMap[id]
scoreMap[id] = score + 1
}
}
diff --git a/internal/server/tcpserver.go b/internal/server/tcpserver.go
index 2eb2422..b6d2ede 100644
--- a/internal/server/tcpserver.go
+++ b/internal/server/tcpserver.go
@@ -61,7 +61,9 @@ func handleConnection(ctx context.Context, conn net.Conn, cb handlerCb) {
log.Println("server: received message", remoteAddr, message)
response := cb(message)
- conn.Write([]byte(response))
+ if _, err := conn.Write([]byte(response)); err != nil {
+ log.Println("error:", err)
+ }
}
}
}