Skip to content

Commit

Permalink
use golangci-lint as linter and fix some linting bugs (#29)
Browse files Browse the repository at this point in the history
use golangci-lint as linter and fix some linting bugs
  • Loading branch information
jandelgado committed Sep 20, 2019
1 parent 8a4367b commit d417517
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 68 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ addons:
- rabbitmq-server

before_install:
- go get -u golang.org/x/lint/golint
- go get github.com/gordonklaus/ineffassign
- go get github.com/fzipp/gocyclo
- go get github.com/client9/misspell/cmd/misspell
- go get golang.org/x/tools/cmd/cover
- go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
- go get github.com/mattn/goveralls

script:
Expand Down
2 changes: 1 addition & 1 deletion cmd/rabtap/cmd_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func cmdInfo(cmd CmdInfoArg) {
renderer := NewBrokerInfoRenderer(cmd.renderConfig)

tree, _ := treeBuilder.BuildTree(cmd.rootNode, brokerInfo)
renderer.Render(tree, os.Stdout)
failOnError(renderer.Render(tree, os.Stdout), "rendering failed", os.Exit)
}
2 changes: 1 addition & 1 deletion cmd/rabtap/cmd_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func cmdPublish(ctx context.Context, cmd CmdPublishArg) error {
// runs as long as readerFunc returns messages. Unfortunately, we
// can not stop a blocking read on a file like we do with channels
// and select.
publishMessageStream(publishChannel, cmd.exchange,
_ = publishMessageStream(publishChannel, cmd.exchange,
cmd.routingKey, cmd.readerFunc)
}()

Expand Down
4 changes: 2 additions & 2 deletions cmd/rabtap/cmd_tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func cmdTap(ctx context.Context, tapConfig []rabtap.TapConfiguration, tlsConfig
// with the main thread, which does the actual message processing
tapMessageChannel := make(rabtap.TapChannel)

taps := []*rabtap.AmqpTap{}
// taps := []*rabtap.AmqpTap{}
for _, config := range tapConfig {
tap := rabtap.NewAmqpTap(config.AmqpURI, tlsConfig, log)
taps = append(taps, tap)
// taps = append(taps, tap)
g.Go(func() error {
return tap.EstablishTap(ctx, config.Exchanges, tapMessageChannel)
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/rabtap/subscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestMessageReceiveLoop(t *testing.T) {
done <- true
return nil
}
go messageReceiveLoop(ctx, messageChan, receiveFunc)
go func() { _ = messageReceiveLoop(ctx, messageChan, receiveFunc) }()

messageChan <- rabtap.TapMessage{}
<-done // TODO add timeout
Expand Down
5 changes: 0 additions & 5 deletions pkg/amqp_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import (
"context"
"crypto/tls"
"errors"
"time"

"github.com/sirupsen/logrus"
)

const (
reconnectDelayTime = 2000 * time.Millisecond
)

// ReconnectAction signals if connection should be reconnected or not.
type ReconnectAction int

Expand Down
2 changes: 1 addition & 1 deletion pkg/fanin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *Fanin) loop() error {
// allow a blocking write to s.Ch to be terminated
select {
case s.Ch <- message.Interface():
case _ = <-s.channels[0].Chan.Interface().(<-chan struct{}):
case <-s.channels[0].Chan.Interface().(<-chan struct{}):
}
}
}
Expand Down
20 changes: 6 additions & 14 deletions pkg/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ func (s *AmqpTap) setupTap(session Session,
tapExchange := getTapExchangeNameForExchange(exchangeConfig.Exchange, id[:12])
tapQueue := getTapQueueNameForExchange(exchangeConfig.Exchange, id[:12])

var err error

err = s.createExchangeToExchangeBinding(session,
err := s.createExchangeToExchangeBinding(session,
exchangeConfig.Exchange,
exchangeConfig.BindingKey,
tapExchange)
Expand Down Expand Up @@ -156,22 +154,16 @@ func (s *AmqpTap) createExchangeToExchangeBinding(session Session,
s.logger.Printf("tap: bind to exchange %s failed with %v", exchangeName, err)
// bind failed, so we must also delete our tap-exchange since it
// will not be auto-deleted when no binding exists.
session.NewChannel()
err2 := RemoveExchange(session, tapExchangeName, false)
s.logger.Printf("delete exchange: %v", err2)
// TODO handle errors
_ = session.NewChannel()
err3 := RemoveExchange(session, tapExchangeName, false)
s.logger.Printf("delete exchange: %v", err3)
return err
}
return nil
}

func (s *AmqpTap) bindQueueToExchange(session Session,
exchangeName, bindingKey, queueName string) error {

var err error

err = BindQueueToExchange(session, queueName, bindingKey, exchangeName)
if err != nil {
return err
}
return nil
return BindQueueToExchange(session, queueName, bindingKey, exchangeName)
}
39 changes: 1 addition & 38 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -1,39 +1,2 @@
#!/bin/sh
MAX_CYCLO=15

INEFFASSIGN_ERRORS=$(ineffassign pkg cmd)
if [ -n "${INEFFASSIGN_ERRORS}" ]; then
printf >&2 'ineffassign failed for the following files:\n%s\n' "${INEFFASSIGN_ERRORS}"
exit 1
fi

MISSPELL_ERRORS=$(misspell pkg/*go cmd/rabtap/*go)
if [ -n "${MISSPELL_ERRORS}" ]; then
printf >&2 'misspell failed for the following files:\n%s\n' "${MISSPELL_ERRORS}"
exit 1
fi

GOCYCLO_ERRORS=$(gocyclo -over $MAX_CYCLO pkg/*go cmd/rabtap/*go)
if [ -n "${GOCYCLO_ERRORS}" ]; then
printf >&2 'gocyclo failed for the following files:\n%s\n' "${GOCYCLO_ERRORS}"
exit 1
fi

GOFMT_FILES=$(gofmt -s -l pkg/*go cmd/rabtap/*go)
if [ -n "${GOFMT_FILES}" ]; then
printf >&2 'gofmt failed for the following files:\n%s\n\nplease run "gofmt -w ." on your changes before committing.\n' "${GOFMT_FILES}"
exit 1
fi

GOLINT_ERRORS=$(golint ./... 2>&1 | grep -v "^vendor/")
if [ -n "${GOLINT_ERRORS}" ]; then
printf >&2 'golint failed for the following reasons:\n%s\n.\n' "${GOLINT_ERRORS}"
exit 1
fi

GOVET_ERRORS=$(go vet pkg/*go 2>&1 && go vet cmd/rabtap/*go 2>&1)
if [ $? -ne 0 ]; then
printf >&2 'go vet failed for the following reasons:\n%s\n\nplease run "go tool vet *.go" on your changes before committing.\n' "${GOVET_ERRORS}"
exit 1
fi

golangci-lint -E bodyclose,misspell,gocyclo,dupl,gofmt,golint,unconvert,goimports,depguard,gocritic,funlen,interfacer run

0 comments on commit d417517

Please sign in to comment.