diff --git a/client/v2/client.go b/client/v2/client.go index 7902b9c20a2..fda25988f6b 100644 --- a/client/v2/client.go +++ b/client/v2/client.go @@ -523,7 +523,7 @@ type simpleHTTPClient struct { // ErrNoRequest indicates that the HTTPRequest object could not be found // or was nil. No processing could continue. -var ErrNoRequest = errors.New("No HTTPRequest was available") +var ErrNoRequest = errors.New("no HTTPRequest was available") func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { req := act.HTTPRequest(c.endpoint) diff --git a/client/v3/client.go b/client/v3/client.go index 7f1f1322ec7..9442c9d1595 100644 --- a/client/v3/client.go +++ b/client/v3/client.go @@ -298,7 +298,7 @@ func (c *Client) credentialsForEndpoint(ep string) grpccredentials.TransportCred } return credentials.NewBundle(credentials.Config{}).TransportCredentials() default: - panic(fmt.Errorf("Unsupported CredsRequirement: %v", r)) + panic(fmt.Errorf("unsupported CredsRequirement: %v", r)) } } diff --git a/client/v3/client_test.go b/client/v3/client_test.go index 5e0f5844c63..159c2f3446f 100644 --- a/client/v3/client_test.go +++ b/client/v3/client_test.go @@ -140,13 +140,13 @@ func TestDialNoTimeout(t *testing.T) { } func TestIsHaltErr(t *testing.T) { - if !isHaltErr(nil, fmt.Errorf("etcdserver: some etcdserver error")) { + if !isHaltErr(context.TODO(), fmt.Errorf("etcdserver: some etcdserver error")) { t.Errorf(`error prefixed with "etcdserver: " should be Halted by default`) } - if isHaltErr(nil, rpctypes.ErrGRPCStopped) { + if isHaltErr(context.TODO(), rpctypes.ErrGRPCStopped) { t.Errorf("error %v should not halt", rpctypes.ErrGRPCStopped) } - if isHaltErr(nil, rpctypes.ErrGRPCNoLeader) { + if isHaltErr(context.TODO(), rpctypes.ErrGRPCNoLeader) { t.Errorf("error %v should not halt", rpctypes.ErrGRPCNoLeader) } ctx, cancel := context.WithCancel(context.TODO()) diff --git a/client/v3/ctx_test.go b/client/v3/ctx_test.go index c0e054341f9..8ba616b76a4 100644 --- a/client/v3/ctx_test.go +++ b/client/v3/ctx_test.go @@ -26,13 +26,13 @@ import ( func TestMetadataWithRequireLeader(t *testing.T) { ctx := context.TODO() - md, ok := metadata.FromOutgoingContext(ctx) + _, ok := metadata.FromOutgoingContext(ctx) if ok { t.Fatal("expected no outgoing metadata ctx key") } // add a conflicting key with some other value - md = metadata.Pairs(rpctypes.MetadataRequireLeaderKey, "invalid") + md := metadata.Pairs(rpctypes.MetadataRequireLeaderKey, "invalid") // add a key, and expect not be overwritten md.Set("hello", "1", "2") ctx = metadata.NewOutgoingContext(ctx, md) diff --git a/client/v3/internal/endpoint/endpoint.go b/client/v3/internal/endpoint/endpoint.go index befe6022bbd..1d3f1a7a2c7 100644 --- a/client/v3/internal/endpoint/endpoint.go +++ b/client/v3/internal/endpoint/endpoint.go @@ -50,7 +50,7 @@ func extractHostFromPath(pathStr string) string { func mustSplit2(s, sep string) (string, string) { spl := strings.SplitN(s, sep, 2) if len(spl) < 2 { - panic(fmt.Errorf("Token '%v' expected to have separator sep: `%v`", s, sep)) + panic(fmt.Errorf("token '%v' expected to have separator sep: `%v`", s, sep)) } return spl[0], spl[1] } diff --git a/client/v3/ordering/kv_test.go b/client/v3/ordering/kv_test.go index 9b5c8ab2c2a..cc5c03bfa6b 100644 --- a/client/v3/ordering/kv_test.go +++ b/client/v3/ordering/kv_test.go @@ -77,7 +77,7 @@ func TestKvOrdering(t *testing.T) { tt.prevRev, sync.RWMutex{}, } - res, err := kv.Get(nil, "mockKey") + res, err := kv.Get(context.TODO(), "mockKey") if err != nil { t.Errorf("#%d: expected response %+v, got error %+v", i, tt.response, err) } diff --git a/client/v3/retry_interceptor.go b/client/v3/retry_interceptor.go index 371c85800d3..1e0f20fd248 100644 --- a/client/v3/retry_interceptor.go +++ b/client/v3/retry_interceptor.go @@ -313,7 +313,7 @@ func isSafeRetry(lg *zap.Logger, err error, callOpts *options) bool { } func isContextError(err error) bool { - return grpc.Code(err) == codes.DeadlineExceeded || grpc.Code(err) == codes.Canceled + return status.Code(err) == codes.DeadlineExceeded || status.Code(err) == codes.Canceled } func contextErrToGrpcErr(err error) error { diff --git a/client/v3/txn_test.go b/client/v3/txn_test.go index 9101b04fa2a..0e755459fc2 100644 --- a/client/v3/txn_test.go +++ b/client/v3/txn_test.go @@ -15,6 +15,7 @@ package clientv3 import ( + "context" "testing" "time" @@ -44,7 +45,7 @@ func TestTxnPanics(t *testing.T) { { f: func() { defer df() - kv.Txn(nil).If(cmp).If(cmp) + kv.Txn(context.TODO()).If(cmp).If(cmp) }, err: "cannot call If twice!", @@ -52,7 +53,7 @@ func TestTxnPanics(t *testing.T) { { f: func() { defer df() - kv.Txn(nil).Then(op).If(cmp) + kv.Txn(context.TODO()).Then(op).If(cmp) }, err: "cannot call If after Then!", @@ -60,7 +61,7 @@ func TestTxnPanics(t *testing.T) { { f: func() { defer df() - kv.Txn(nil).Else(op).If(cmp) + kv.Txn(context.TODO()).Else(op).If(cmp) }, err: "cannot call If after Else!", @@ -68,7 +69,7 @@ func TestTxnPanics(t *testing.T) { { f: func() { defer df() - kv.Txn(nil).Then(op).Then(op) + kv.Txn(context.TODO()).Then(op).Then(op) }, err: "cannot call Then twice!", @@ -76,7 +77,7 @@ func TestTxnPanics(t *testing.T) { { f: func() { defer df() - kv.Txn(nil).Else(op).Then(op) + kv.Txn(context.TODO()).Else(op).Then(op) }, err: "cannot call Then after Else!", @@ -84,7 +85,7 @@ func TestTxnPanics(t *testing.T) { { f: func() { defer df() - kv.Txn(nil).Else(op).Else(op) + kv.Txn(context.TODO()).Else(op).Else(op) }, err: "cannot call Else twice!", diff --git a/etcdctl/ctlv2/command/exec_watch_command.go b/etcdctl/ctlv2/command/exec_watch_command.go index 2bded023214..58f8b529fb3 100644 --- a/etcdctl/ctlv2/command/exec_watch_command.go +++ b/etcdctl/ctlv2/command/exec_watch_command.go @@ -109,7 +109,7 @@ func execWatchCommandFunc(c *cli.Context, ki client.KeysAPI) { go func() { err := cmd.Start() if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } cmd.Wait() diff --git a/etcdctl/ctlv3/command/ep_command.go b/etcdctl/ctlv3/command/ep_command.go index 589a76aa77b..c286e896e06 100644 --- a/etcdctl/ctlv3/command/ep_command.go +++ b/etcdctl/ctlv3/command/ep_command.go @@ -133,7 +133,7 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) { eh.Error = err.Error() } - if eh.Health == true { + if eh.Health { resp, err := cli.AlarmList(ctx) if err == nil && len(resp.Alarms) > 0 { eh.Health = false diff --git a/etcdctl/ctlv3/command/printer_json.go b/etcdctl/ctlv3/command/printer_json.go index 4d9732b95e4..22bc4f482c1 100644 --- a/etcdctl/ctlv3/command/printer_json.go +++ b/etcdctl/ctlv3/command/printer_json.go @@ -98,6 +98,6 @@ func printMemberListWithHexJSON(r clientv3.MemberListResponse) { } } buffer.WriteString("}") - fmt.Println(string(buffer.Bytes())) + fmt.Println(buffer.String()) } diff --git a/etcdctl/ctlv3/command/watch_command.go b/etcdctl/ctlv3/command/watch_command.go index 1697511f59c..1bfc479b149 100644 --- a/etcdctl/ctlv3/command/watch_command.go +++ b/etcdctl/ctlv3/command/watch_command.go @@ -98,7 +98,7 @@ func watchInteractiveFunc(cmd *cobra.Command, osArgs []string, envKey, envRange for { l, err := reader.ReadString('\n') if err != nil { - ExitWithError(ExitInvalidInput, fmt.Errorf("Error reading watch request line: %v", err)) + ExitWithError(ExitInvalidInput, fmt.Errorf("error reading watch request line: %v", err)) } l = strings.TrimSuffix(l, "\n") diff --git a/pkg/fileutil/fileutil.go b/pkg/fileutil/fileutil.go index 657d5584163..f4b1986424d 100644 --- a/pkg/fileutil/fileutil.go +++ b/pkg/fileutil/fileutil.go @@ -121,7 +121,7 @@ func ZeroToEnd(f *os.File) error { // Returns error if dir is empty or exist with a different permission than specified. func CheckDirPermission(dir string, perm os.FileMode) error { if !Exist(dir) { - return fmt.Errorf("directory %q empty, cannot check permission.", dir) + return fmt.Errorf("directory %q empty, cannot check permission", dir) } //check the existing permission on the directory dirInfo, err := os.Stat(dir) @@ -130,7 +130,7 @@ func CheckDirPermission(dir string, perm os.FileMode) error { } dirMode := dirInfo.Mode().Perm() if dirMode != perm { - err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data.", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode)) + err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode)) return err } return nil diff --git a/pkg/transport/transport.go b/pkg/transport/transport.go index 4a7fe69d2e1..949610d46c1 100644 --- a/pkg/transport/transport.go +++ b/pkg/transport/transport.go @@ -41,10 +41,10 @@ func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, er TLSClientConfig: cfg, } - dialer := (&net.Dialer{ + dialer := &net.Dialer{ Timeout: dialtimeoutd, KeepAlive: 30 * time.Second, - }) + } dial := func(net, addr string) (net.Conn, error) { return dialer.Dial("unix", addr) } diff --git a/raft/confchange/confchange.go b/raft/confchange/confchange.go index 85689b44884..55e6830ce8a 100644 --- a/raft/confchange/confchange.go +++ b/raft/confchange/confchange.go @@ -188,7 +188,6 @@ func (c Changer) makeVoter(cfg *tracker.Config, prs tracker.ProgressMap, id uint nilAwareDelete(&cfg.Learners, id) nilAwareDelete(&cfg.LearnersNext, id) incoming(cfg.Voters)[id] = struct{}{} - return } // makeLearner makes the given ID a learner or stages it to be a learner once @@ -321,10 +320,10 @@ func checkInvariants(cfg tracker.Config, prs tracker.ProgressMap) error { if !joint(cfg) { // We enforce that empty maps are nil instead of zero. if outgoing(cfg.Voters) != nil { - return fmt.Errorf("Voters[1] must be nil when not joint") + return fmt.Errorf("cfg.Voters[1] must be nil when not joint") } if cfg.LearnersNext != nil { - return fmt.Errorf("LearnersNext must be nil when not joint") + return fmt.Errorf("cfg.LearnersNext must be nil when not joint") } if cfg.AutoLeave { return fmt.Errorf("AutoLeave must be false when not joint") diff --git a/raft/quorum/datadriven_test.go b/raft/quorum/datadriven_test.go index 50dbb25af62..b40eaa76c69 100644 --- a/raft/quorum/datadriven_test.go +++ b/raft/quorum/datadriven_test.go @@ -169,7 +169,7 @@ func TestDataDriven(t *testing.T) { // test case. if !joint { idx := c.CommittedIndex(l) - fmt.Fprintf(&buf, c.Describe(l)) + fmt.Fprint(&buf, c.Describe(l)) // These alternative computations should return the same // result. If not, print to the output. if aIdx := alternativeMajorityCommittedIndex(c, l); aIdx != idx { @@ -213,7 +213,7 @@ func TestDataDriven(t *testing.T) { fmt.Fprintf(&buf, "%s\n", idx) } else { cc := JointConfig([2]MajorityConfig{c, cj}) - fmt.Fprintf(&buf, cc.Describe(l)) + fmt.Fprint(&buf, cc.Describe(l)) idx := cc.CommittedIndex(l) // Interchanging the majorities shouldn't make a difference. If it does, print. if aIdx := JointConfig([2]MajorityConfig{cj, c}).CommittedIndex(l); aIdx != idx { diff --git a/raft/quorum/quick_test.go b/raft/quorum/quick_test.go index 45fb6b00a74..d838b54f8c3 100644 --- a/raft/quorum/quick_test.go +++ b/raft/quorum/quick_test.go @@ -44,10 +44,10 @@ func TestQuick(t *testing.T) { } // smallRandIdxMap returns a reasonably sized map of ids to commit indexes. -func smallRandIdxMap(rand *rand.Rand, size int) map[uint64]Index { +func smallRandIdxMap(rand *rand.Rand, _ int) map[uint64]Index { // Hard-code a reasonably small size here (quick will hard-code 50, which // is not useful here). - size = 10 + size := 10 n := rand.Intn(size) ids := rand.Perm(2 * n)[:n] diff --git a/raft/rafttest/interaction_env_handler_log_level.go b/raft/rafttest/interaction_env_handler_log_level.go index a61ba37cd89..2194c9ee1a1 100644 --- a/raft/rafttest/interaction_env_handler_log_level.go +++ b/raft/rafttest/interaction_env_handler_log_level.go @@ -28,7 +28,7 @@ func (env *InteractionEnv) handleLogLevel(t *testing.T, d datadriven.TestData) e func (env *InteractionEnv) LogLevel(name string) error { for i, s := range lvlNames { - if strings.ToLower(s) == strings.ToLower(name) { + if strings.EqualFold(s, name) { env.Output.Lvl = i return nil } diff --git a/raft/rafttest/interaction_env_handler_process_ready.go b/raft/rafttest/interaction_env_handler_process_ready.go index c0014d7e01b..d94ac60334f 100644 --- a/raft/rafttest/interaction_env_handler_process_ready.go +++ b/raft/rafttest/interaction_env_handler_process_ready.go @@ -99,9 +99,9 @@ func (env *InteractionEnv) ProcessReady(idx int) error { snap.Metadata.ConfState = *cs env.Nodes[idx].History = append(env.Nodes[idx].History, snap) } - for _, msg := range rd.Messages { - env.Messages = append(env.Messages, msg) - } + + env.Messages = append(env.Messages, rd.Messages...) + rn.Advance(rd) return nil } diff --git a/raft/rafttest/node.go b/raft/rafttest/node.go index 2dfeca5307b..cb1a1241fcd 100644 --- a/raft/rafttest/node.go +++ b/raft/rafttest/node.go @@ -64,7 +64,7 @@ func startNode(id uint64, peers []raft.Peer, iface iface) *node { func (n *node) start() { n.stopc = make(chan struct{}) - ticker := time.Tick(5 * time.Millisecond) + ticker := time.NewTicker(5 * time.Millisecond).C go func() { for { diff --git a/raft/rawnode_test.go b/raft/rawnode_test.go index 0fe03512f91..898b0f12c3e 100644 --- a/raft/rawnode_test.go +++ b/raft/rawnode_test.go @@ -467,7 +467,7 @@ func TestRawNodeJointAutoLeave(t *testing.T) { t.Fatalf("exp:\n%+v\nact:\n%+v", expCs, cs) } - if 0 != rawNode.raft.pendingConfIndex { + if rawNode.raft.pendingConfIndex != 0 { t.Fatalf("pendingConfIndex: expected %d, got %d", 0, rawNode.raft.pendingConfIndex) } diff --git a/raft/status.go b/raft/status.go index d7c7a4fa7ae..acfb56c3915 100644 --- a/raft/status.go +++ b/raft/status.go @@ -44,8 +44,7 @@ type BasicStatus struct { func getProgressCopy(r *raft) map[uint64]tracker.Progress { m := make(map[uint64]tracker.Progress) r.prs.Visit(func(id uint64, pr *tracker.Progress) { - var p tracker.Progress - p = *pr + p := *pr p.Inflights = pr.Inflights.Clone() pr = nil diff --git a/raft/tracker/tracker.go b/raft/tracker/tracker.go index 13a0dc09465..72dcc73b866 100644 --- a/raft/tracker/tracker.go +++ b/raft/tracker/tracker.go @@ -194,7 +194,7 @@ func (p *ProgressTracker) Visit(f func(id uint64, pr *Progress)) { // The optimization here mirrors that in `(MajorityConfig).CommittedIndex`, // see there for details. var sl [7]uint64 - ids := sl[:] + var ids []uint64 if len(sl) >= n { ids = sl[:n] } else {