Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gofumpt #1741

Merged
merged 7 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ linters:
# - cyclop # not interested in package complexities at the moment
# - godot
- gofmt
# - gofumpt
- gofumpt
- goheader
- goimports
- revive
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ test-integration:
docker compose -f test/docker-compose-postgres.yml -f test/docker-compose-schemaregistry.yml down; \
exit $$ret

.PHONY: fmt
fmt:
gofumpt -l -w .

.PHONY: lint
lint:
golangci-lint run -v
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
mvdan.cc/gofumpt v0.6.0
)

require (
Expand Down Expand Up @@ -354,6 +355,5 @@ require (
modernc.org/sqlite v1.31.1 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
mvdan.cc/gofumpt v0.6.0 // indirect
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
)
55 changes: 28 additions & 27 deletions pkg/connector/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,34 +248,35 @@ func TestService_CreateError(t *testing.T) {
plugin string
pipelineID string
data Config
}{{
name: "invalid connector type",
connType: 0,
plugin: "test-plugin",
pipelineID: uuid.NewString(),
data: Config{
Name: "test-connector",
Settings: map[string]string{"foo": "bar"},
},
}, {
name: "empty plugin",
connType: TypeSource,
plugin: "",
pipelineID: uuid.NewString(),
data: Config{
Name: "test-connector",
Settings: map[string]string{"foo": "bar"},
},
}, {
name: "empty pipeline ID",
connType: TypeSource,
plugin: "test-plugin",
pipelineID: "",
data: Config{
Name: "test-connector",
Settings: map[string]string{"foo": "bar"},
}{
{
name: "invalid connector type",
connType: 0,
plugin: "test-plugin",
pipelineID: uuid.NewString(),
data: Config{
Name: "test-connector",
Settings: map[string]string{"foo": "bar"},
},
}, {
name: "empty plugin",
connType: TypeSource,
plugin: "",
pipelineID: uuid.NewString(),
data: Config{
Name: "test-connector",
Settings: map[string]string{"foo": "bar"},
},
}, {
name: "empty pipeline ID",
connType: TypeSource,
plugin: "test-plugin",
pipelineID: "",
data: Config{
Name: "test-connector",
Settings: map[string]string{"foo": "bar"},
},
},
},
}

for _, tt := range testCases {
Expand Down
13 changes: 6 additions & 7 deletions pkg/foundation/cerrors/cerrors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import (

var _, testFileLocation, _, _ = runtime.Caller(0)

type secretError struct {
}
type secretError struct{}

func (s *secretError) Error() string {
return "secret error message"
}

type unwrapPanicError struct {
}
type unwrapPanicError struct{}

func (w *unwrapPanicError) Error() string {
return "calling Unwrap() will panic"
Expand Down Expand Up @@ -61,7 +59,7 @@ func TestErrorf(t *testing.T) {
s := fmt.Sprintf("%+v", err)
is.Equal(
"caused by:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.TestErrorf\n "+
testFileLocation+":60\n - "+
testFileLocation+":58\n - "+
"foobar:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.newError\n "+
helperFilePath+":26",
s,
Expand Down Expand Up @@ -91,7 +89,7 @@ func TestGetStackTrace(t *testing.T) {
{
Func: "github.com/conduitio/conduit/pkg/foundation/cerrors_test.TestGetStackTrace",
File: testFileLocation,
Line: 89,
Line: 87,
},
},
},
Expand Down Expand Up @@ -183,7 +181,8 @@ func TestLogOrReplace(t *testing.T) {
newErr: errBar,
wantErr: errFoo,
wantLogCalled: true,
}}
},
}

for testName, tc := range testCases {
t.Run(testName, func(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/foundation/grpcutil/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const (

func HeaderMatcher(key string) (string, bool) {
switch strings.ToLower(key) {
case RequestIDHeader,
HTTPEndpointHeader:
case RequestIDHeader, HTTPEndpointHeader:
return key, true
default:
return runtime.DefaultHeaderMatcher(key)
Expand Down
2 changes: 2 additions & 0 deletions pkg/foundation/grpcutil/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func newInMemoryResponseWriter(writer io.Writer) *inMemoryResponseWriter {
func (w *inMemoryResponseWriter) Write(b []byte) (int, error) {
return w.Writer.Write(b)
}

func (w *inMemoryResponseWriter) Header() http.Header {
return w.header
}

func (w *inMemoryResponseWriter) WriteHeader(int) {
// we don't have a use for the code
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/foundation/log/ctxlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test(t testing.TB) CtxLogger {

// InitLogger returns a logger initialized with the wanted level and format
func InitLogger(level zerolog.Level, f Format) CtxLogger {
var w = GetWriter(f)
w := GetWriter(f)
logger := zerolog.New(w).
With().
Timestamp().
Expand Down
21 changes: 15 additions & 6 deletions pkg/foundation/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ type LabeledHistogram interface {
WithValues(labels ...string) Histogram
}

var (
global = struct {
metrics []metric
registries []Registry
}{}
)
var global = struct {
metrics []metric
registries []Registry
}{}

// Register adds a Registry to the global registries. Any metrics that were
// created prior or after this call will also be created in this registry. This
Expand Down Expand Up @@ -243,6 +241,7 @@ func (mt *counter) New(r Registry) {
m := r.NewCounter(mt.name, mt.help, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *counter) Inc(vs ...float64) {
for _, m := range mt.metrics {
m.Inc(vs...)
Expand All @@ -258,6 +257,7 @@ func (mt *labeledCounter) New(r Registry) {
m := r.NewLabeledCounter(mt.name, mt.help, mt.labels, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *labeledCounter) WithValues(vs ...string) Counter {
c := &counter{
spec: mt.spec,
Expand All @@ -278,16 +278,19 @@ func (mt *gauge) New(r Registry) {
m := r.NewGauge(mt.name, mt.help, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *gauge) Inc(f ...float64) {
for _, m := range mt.metrics {
m.Inc(f...)
}
}

func (mt *gauge) Dec(f ...float64) {
for _, m := range mt.metrics {
m.Dec(f...)
}
}

func (mt *gauge) Set(f float64) {
for _, m := range mt.metrics {
m.Set(f)
Expand All @@ -303,6 +306,7 @@ func (mt *labeledGauge) New(r Registry) {
m := r.NewLabeledGauge(mt.name, mt.help, mt.labels, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *labeledGauge) WithValues(vs ...string) Gauge {
g := &gauge{
spec: mt.spec,
Expand All @@ -323,11 +327,13 @@ func (mt *timer) New(r Registry) {
m := r.NewTimer(mt.name, mt.help, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *timer) Update(d time.Duration) {
for _, m := range mt.metrics {
m.Update(d)
}
}

func (mt *timer) UpdateSince(t time.Time) {
for _, m := range mt.metrics {
m.UpdateSince(t)
Expand All @@ -343,6 +349,7 @@ func (mt *labeledTimer) New(r Registry) {
m := r.NewLabeledTimer(mt.name, mt.help, mt.labels, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *labeledTimer) WithValues(vs ...string) Timer {
t := &timer{
spec: mt.spec,
Expand All @@ -363,6 +370,7 @@ func (mt *histogram) New(r Registry) {
m := r.NewHistogram(mt.name, mt.help, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *histogram) Observe(v float64) {
for _, m := range mt.metrics {
m.Observe(v)
Expand All @@ -378,6 +386,7 @@ func (mt *labeledHistogram) New(r Registry) {
m := r.NewLabeledHistogram(mt.name, mt.help, mt.labels, mt.opts...)
mt.metrics = append(mt.metrics, m)
}

func (mt *labeledHistogram) WithValues(vs ...string) Histogram {
t := &histogram{
spec: mt.spec,
Expand Down
3 changes: 3 additions & 0 deletions pkg/foundation/metrics/prometheus/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (r *Registry) newCounterOpts(name, help string, opts []metrics.Option) prom
opts,
)
}

func (r *Registry) applyCounterOptions(promOpts prometheus.CounterOpts, metricsOpts []metrics.Option) prometheus.CounterOpts {
for _, mopt := range metricsOpts {
opt, ok := mopt.(option)
Expand Down Expand Up @@ -102,6 +103,7 @@ func (r *Registry) newGaugeOpts(name, help string, opts []metrics.Option) promet
opts,
)
}

func (r *Registry) applyGaugeOptions(promOpts prometheus.GaugeOpts, metricsOpts []metrics.Option) prometheus.GaugeOpts {
for _, mopt := range metricsOpts {
opt, ok := mopt.(option)
Expand Down Expand Up @@ -156,6 +158,7 @@ func (r *Registry) newHistogramOpts(name, help string, opts []metrics.Option) pr
opts,
)
}

func (r *Registry) applyHistogramOptions(promOpts prometheus.HistogramOpts, metricsOpts []metrics.Option) prometheus.HistogramOpts {
for _, mopt := range metricsOpts {
opt, ok := mopt.(option)
Expand Down
1 change: 1 addition & 0 deletions pkg/pipeline/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func (s *Service) notify(pipelineID string, err error) {
handler(e)
}
}

func (s *Service) validatePipeline(cfg Config, id string) error {
// contains all the errors occurred while provisioning configuration files.
var errs []error
Expand Down
3 changes: 1 addition & 2 deletions pkg/pipeline/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"github.com/matryer/is"
)

type boringError struct {
}
type boringError struct{}

func (e boringError) Error() string {
return "a very, very boring error"
Expand Down
4 changes: 1 addition & 3 deletions pkg/pipeline/stream/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const (
MessageStatusOpen
)

var (
ErrUnexpectedMessageStatus = cerrors.New("unexpected message status")
)
var ErrUnexpectedMessageStatus = cerrors.New("unexpected message status")

// Message represents a single message flowing through a pipeline. Only a single
// node is allowed to hold a message and access its fields at a specific point
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/stream/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ func (n *parallelTestNode) Pub() <-chan *Message {
n.pub = make(chan *Message)
return n.pub
}

func (n *parallelTestNode) Sub(in <-chan *Message) {
n.sub = in
}

func (n *parallelTestNode) Run(ctx context.Context) error {
return n.F(ctx, n.sub, n.pub)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/stream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ type gomockLogger log.CtxLogger
func (g gomockLogger) Errorf(format string, args ...interface{}) {
g.Error().Msgf(format, args...)
}

func (g gomockLogger) Fatalf(format string, args ...interface{}) {
g.Fatal().Msgf(format, args...)
}
Expand All @@ -453,6 +454,7 @@ type eqMatcherLazy struct {
func (e eqMatcherLazy) Matches(x interface{}) bool {
return gomock.Eq(e.x()).Matches(x)
}

func (e eqMatcherLazy) String() string {
return gomock.Eq(e.x()).String()
}
3 changes: 2 additions & 1 deletion pkg/plugin/connector/builtin/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func newDestinationPluginAdapter(impl pconnector.DestinationPlugin, logger log.C
return &destinationPluginAdapter{
impl: impl,
logger: logger.WithComponent("builtin.destinationPluginAdapter"),
ctxLogger: logger.WithComponent("plugin").ZerologWithComponent()}
ctxLogger: logger.WithComponent("plugin").ZerologWithComponent(),
}
}

func (d *destinationPluginAdapter) withLogger(ctx context.Context) context.Context {
Expand Down
24 changes: 11 additions & 13 deletions pkg/plugin/connector/builtin/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ import (
"github.com/conduitio/conduit/pkg/plugin/connector/connutils"
)

var (
// DefaultBuiltinConnectors contains the default built-in connectors.
// The key of the map is the import path of the module
// containing the connector implementation.
DefaultBuiltinConnectors = map[string]sdk.Connector{
"github.com/conduitio/conduit-connector-file": file.Connector,
"github.com/conduitio/conduit-connector-generator": generator.Connector,
"github.com/conduitio/conduit-connector-kafka": kafka.Connector,
"github.com/conduitio/conduit-connector-log": connLog.Connector,
"github.com/conduitio/conduit-connector-postgres": postgres.Connector,
"github.com/conduitio/conduit-connector-s3": s3.Connector,
}
)
// DefaultBuiltinConnectors contains the default built-in connectors.
// The key of the map is the import path of the module
// containing the connector implementation.
var DefaultBuiltinConnectors = map[string]sdk.Connector{
"github.com/conduitio/conduit-connector-file": file.Connector,
"github.com/conduitio/conduit-connector-generator": generator.Connector,
"github.com/conduitio/conduit-connector-kafka": kafka.Connector,
"github.com/conduitio/conduit-connector-log": connLog.Connector,
"github.com/conduitio/conduit-connector-postgres": postgres.Connector,
"github.com/conduitio/conduit-connector-s3": s3.Connector,
}

type Registry struct {
logger log.CtxLogger
Expand Down
Loading