Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Sep 9, 2022
1 parent e8fa2d2 commit 941c11e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Raft

[![Build Status](https://github.com/bbengfort/raft/actions/workflows/test.yaml/badge.svg?branch=main)
[![Build Status](https://github.com/bbengfort/raft/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/bbengfort/raft/actions/workflows/test.yaml)
[![GoDoc](https://godoc.org/github.com/bbengfort/raft?status.svg)](https://pkg.go.dev/github.com/bbengfort/raft)

**Actor based implementation of the [Raft consensus algorithm](https://raft.github.io/)**.
Expand Down
5 changes: 4 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ func (c *Client) connect(remote string) (err error) {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

// Connect to the remote's address
addr := host.Endpoint(false)
if c.conn, err = grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(timeout)); err != nil {
if c.conn, err = grpc.DialContext(ctx, addr, grpc.WithInsecure()); err != nil {
return fmt.Errorf("could not connect to '%s': %s", addr, err.Error())
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/raft/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"runtime"
Expand Down Expand Up @@ -154,13 +153,13 @@ func main() {

func initConfig(c *cli.Context) (err error) {
if c.String("config") != "" {
data, err := ioutil.ReadFile(c.String("config"))
if err != nil {
return cli.NewExitError(err.Error(), 1)
var f *os.File
if f, err = os.Open(c.String("config")); err != nil {
return cli.NewExitError(err, 1)
}

if err = json.Unmarshal(data, &config); err != nil {
return cli.NewExitError(err.Error(), 1)
if err = json.NewDecoder(f).Decode(&config); err != nil {
return cli.NewExitError(err, 1)
}
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ func print(level uint8, msg string, a ...interface{}) {

// Prints to the standard logger if level is warn or greater; arguments are
// handled in the manner of log.Printf, but a newline is appended.
//
//lint:ignore U1000 keeping this function stub for future use.
func warn(msg string, a ...interface{}) {
print(LogWarn, msg, a...)
}

// Helper function to simply warn about an error received.
//
//lint:ignore U1000 keeping this function stub for future use.
func warne(err error) {
warn(err.Error())
}
Expand Down
3 changes: 1 addition & 2 deletions events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func (e *testEvent) Value() interface{} {
var _ = Describe("Events", func() {

It("should be able to assign mock event to EventType", func() {
var event Event
event = &testEvent{} // this will fail before the assertion but is a good sanity check
var event Event = &testEvent{} // this will fail before the assertion but is a good sanity check
Ω(&testEvent{}).Should(BeAssignableToTypeOf(event))
})

Expand Down
6 changes: 3 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func (l *Log) Create(name string, value []byte, term uint64) (*pb.LogEntry, erro
// an entry creates a log inconsistency (out of order term or index), then an
// error is returned. A couple of important notes:
//
// 1. Append does not undo any successful appends even on error
// 2. Append will not compare entries that specify the same index
// 1. Append does not undo any successful appends even on error
// 2. Append will not compare entries that specify the same index
//
// These notes mean that all entries being appended to this log should be
// consistent with each other as well as the end of the log, and that the log
Expand Down Expand Up @@ -189,7 +189,7 @@ func (l *Log) Commit(index uint64) error {
// entry at the specified index; e.g. truncate after.
func (l *Log) Truncate(index, term uint64) error {
// Ensure the truncation matches an entry
if index < 0 || index > l.lastApplied {
if index > l.lastApplied {
return fmt.Errorf("cannot truncate invalid index %d", index)
}

Expand Down
18 changes: 9 additions & 9 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("Log", func() {
Index: 1,
Term: 42,
Name: "foo",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
}

err := log.Append(entry)
Expand All @@ -87,25 +87,25 @@ var _ = Describe("Log", func() {
Index: 1,
Term: 42,
Name: "foo",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
{
Index: 2,
Term: 42,
Name: "bar",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
{
Index: 3,
Term: 42,
Name: "baz",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
{
Index: 4,
Term: 42,
Name: "zop",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
}

Expand Down Expand Up @@ -229,25 +229,25 @@ var _ = Describe("Log", func() {
Index: lastIdx + 1,
Term: term,
Name: "foo",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
{
Index: lastIdx + 2,
Term: term,
Name: "bar",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
{
Index: lastIdx + 3,
Term: term,
Name: "baz",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
{
Index: lastIdx + 4,
Term: term,
Name: "zop",
Value: []byte(fmt.Sprintf("%s", time.Now())),
Value: []byte(time.Now().Format(time.RFC3339Nano)),
},
}

Expand Down
6 changes: 2 additions & 4 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ func (m *Metrics) Dump(path string, extra map[string]interface{}) (err error) {
data := make(map[string]interface{})

// Append extra information
if extra != nil {
for key, val := range extra {
data[key] = val
}
for key, val := range extra {
data[key] = val
}

data["metric"] = "server"
Expand Down
1 change: 1 addition & 0 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
cautionCounter.init()

// Stop the grpc verbose logging
//lint:ignore SA1019 noplog doesn't implement the V2 interface
grpclog.SetLogger(noplog.New())
}

Expand Down
6 changes: 5 additions & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ func (c *Remote) AppendEntries(leader string, term uint64, log *Log) error {
// explicitly called, but is instead connected when a message is sent.
func (c *Remote) Connect() (err error) {
addr := c.Endpoint(true)
ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
defer cancel()

if c.conn, err = grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(c.timeout)); err != nil {
if c.conn, err = grpc.DialContext(ctx, addr, grpc.WithInsecure()); err != nil {
return fmt.Errorf("could not connect to '%s': %s", addr, err.Error())
}

Expand Down Expand Up @@ -258,6 +260,8 @@ func (c *Remote) afterSend(err error) error {

// Dispatch fatal errors as an error event to the actor, in a go routine so
// that the remote can still be accessed or managed (e.g. closed).
//
//lint:ignore U1000 keeping this function stub for future use.
func (c *Remote) error(err error) {
go func() {
c.actor.Dispatch(&event{
Expand Down

0 comments on commit 941c11e

Please sign in to comment.