From 1a6d7b3ef692e9c49b2cc8018ee3593ea2ebc0f7 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Thu, 22 Sep 2022 22:40:01 +0800 Subject: [PATCH] chore: gofumpt (#2439) --- core/discov/internal/registry_test.go | 2 +- core/mapping/yamlunmarshaler.go | 2 +- core/mr/mapreduce_fuzz_test.go | 2 +- core/stores/mon/collection.go | 22 +++++++++++----------- core/stores/mon/collection_test.go | 8 ++++---- core/stores/mon/model.go | 4 ++-- core/stores/monc/cachedmodel.go | 16 ++++++++-------- tools/goctl/api/docgen/doc.go | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/core/discov/internal/registry_test.go b/core/discov/internal/registry_test.go index 0839cb1e3076..0ebc00caaf67 100644 --- a/core/discov/internal/registry_test.go +++ b/core/discov/internal/registry_test.go @@ -2,7 +2,6 @@ package internal import ( "context" - "go.etcd.io/etcd/api/v3/etcdserverpb" "sync" "testing" @@ -12,6 +11,7 @@ import ( "github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stringx" + "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/mvccpb" clientv3 "go.etcd.io/etcd/client/v3" ) diff --git a/core/mapping/yamlunmarshaler.go b/core/mapping/yamlunmarshaler.go index 4c41ddfbc65f..9ae892146a7e 100644 --- a/core/mapping/yamlunmarshaler.go +++ b/core/mapping/yamlunmarshaler.go @@ -63,7 +63,7 @@ func cleanupMapValue(v interface{}) interface{} { } } -func unmarshal(unmarshaler *Unmarshaler, o interface{}, v interface{}) error { +func unmarshal(unmarshaler *Unmarshaler, o, v interface{}) error { if m, ok := o.(map[string]interface{}); ok { return unmarshaler.Unmarshal(m, v) } diff --git a/core/mr/mapreduce_fuzz_test.go b/core/mr/mapreduce_fuzz_test.go index fa930a505122..fc336a957906 100644 --- a/core/mr/mapreduce_fuzz_test.go +++ b/core/mr/mapreduce_fuzz_test.go @@ -19,7 +19,7 @@ func FuzzMapReduce(f *testing.F) { rand.Seed(time.Now().UnixNano()) f.Add(uint(10), uint(runtime.NumCPU())) - f.Fuzz(func(t *testing.T, num uint, workers uint) { + f.Fuzz(func(t *testing.T, num, workers uint) { n := int64(num)%5000 + 5000 genPanic := rand.Intn(100) == 0 mapperPanic := rand.Intn(100) == 0 diff --git a/core/stores/mon/collection.go b/core/stores/mon/collection.go index 556ad31d9b87..229d83ccf884 100644 --- a/core/stores/mon/collection.go +++ b/core/stores/mon/collection.go @@ -83,12 +83,12 @@ type ( // FindOneAndReplace returns at most one document that matches the filter. If the filter // matches multiple documents, FindOneAndReplace returns the first document in the // collection that matches the filter. - FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{}, + FindOneAndReplace(ctx context.Context, filter, replacement interface{}, opts ...*mopt.FindOneAndReplaceOptions) (*mongo.SingleResult, error) // FindOneAndUpdate returns at most one document that matches the filter. If the filter // matches multiple documents, FindOneAndUpdate returns the first document in the // collection that matches the filter. - FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, + FindOneAndUpdate(ctx context.Context, filter, update interface{}, opts ...*mopt.FindOneAndUpdateOptions) (*mongo.SingleResult, error) // Indexes returns the index view for this collection. Indexes() mongo.IndexView @@ -99,16 +99,16 @@ type ( InsertOne(ctx context.Context, document interface{}, opts ...*mopt.InsertOneOptions) ( *mongo.InsertOneResult, error) // ReplaceOne replaces at most one document that matches the filter. - ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, + ReplaceOne(ctx context.Context, filter, replacement interface{}, opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error) // UpdateByID updates a single document matching the provided filter. - UpdateByID(ctx context.Context, id interface{}, update interface{}, + UpdateByID(ctx context.Context, id, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) // UpdateMany updates the provided documents. - UpdateMany(ctx context.Context, filter interface{}, update interface{}, + UpdateMany(ctx context.Context, filter, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) // UpdateOne updates a single document matching the provided filter. - UpdateOne(ctx context.Context, filter interface{}, update interface{}, + UpdateOne(ctx context.Context, filter, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) // Watch returns a change stream cursor used to receive notifications of changes to the collection. Watch(ctx context.Context, pipeline interface{}, opts ...*mopt.ChangeStreamOptions) ( @@ -359,7 +359,7 @@ func (c *decoratedCollection) FindOneAndReplace(ctx context.Context, filter inte return } -func (c *decoratedCollection) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, +func (c *decoratedCollection) FindOneAndUpdate(ctx context.Context, filter, update interface{}, opts ...*mopt.FindOneAndUpdateOptions) (res *mongo.SingleResult, err error) { ctx, span := startSpan(ctx, findOneAndUpdate) defer func() { @@ -420,7 +420,7 @@ func (c *decoratedCollection) InsertOne(ctx context.Context, document interface{ return } -func (c *decoratedCollection) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, +func (c *decoratedCollection) ReplaceOne(ctx context.Context, filter, replacement interface{}, opts ...*mopt.ReplaceOptions) (res *mongo.UpdateResult, err error) { ctx, span := startSpan(ctx, replaceOne) defer func() { @@ -440,7 +440,7 @@ func (c *decoratedCollection) ReplaceOne(ctx context.Context, filter interface{} return } -func (c *decoratedCollection) UpdateByID(ctx context.Context, id interface{}, update interface{}, +func (c *decoratedCollection) UpdateByID(ctx context.Context, id, update interface{}, opts ...*mopt.UpdateOptions) (res *mongo.UpdateResult, err error) { ctx, span := startSpan(ctx, updateByID) defer func() { @@ -460,7 +460,7 @@ func (c *decoratedCollection) UpdateByID(ctx context.Context, id interface{}, up return } -func (c *decoratedCollection) UpdateMany(ctx context.Context, filter interface{}, update interface{}, +func (c *decoratedCollection) UpdateMany(ctx context.Context, filter, update interface{}, opts ...*mopt.UpdateOptions) (res *mongo.UpdateResult, err error) { ctx, span := startSpan(ctx, updateMany) defer func() { @@ -480,7 +480,7 @@ func (c *decoratedCollection) UpdateMany(ctx context.Context, filter interface{} return } -func (c *decoratedCollection) UpdateOne(ctx context.Context, filter interface{}, update interface{}, +func (c *decoratedCollection) UpdateOne(ctx context.Context, filter, update interface{}, opts ...*mopt.UpdateOptions) (res *mongo.UpdateResult, err error) { ctx, span := startSpan(ctx, updateOne) defer func() { diff --git a/core/stores/mon/collection_test.go b/core/stores/mon/collection_test.go index 225f008fe3fe..b8a0f88064d7 100644 --- a/core/stores/mon/collection_test.go +++ b/core/stores/mon/collection_test.go @@ -106,14 +106,14 @@ func TestCollection_BulkWrite(t *testing.T) { } mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...)) res, err := c.BulkWrite(context.Background(), []mongo.WriteModel{ - mongo.NewInsertOneModel().SetDocument(bson.D{{Key: "foo", Value: 1}})}, - ) + mongo.NewInsertOneModel().SetDocument(bson.D{{Key: "foo", Value: 1}}), + }) assert.Nil(t, err) assert.NotNil(t, res) c.brk = new(dropBreaker) _, err = c.BulkWrite(context.Background(), []mongo.WriteModel{ - mongo.NewInsertOneModel().SetDocument(bson.D{{Key: "foo", Value: 1}})}, - ) + mongo.NewInsertOneModel().SetDocument(bson.D{{Key: "foo", Value: 1}}), + }) assert.Equal(t, errDummy, err) }) } diff --git a/core/stores/mon/model.go b/core/stores/mon/model.go index c963f988dae5..1f27ff725945 100644 --- a/core/stores/mon/model.go +++ b/core/stores/mon/model.go @@ -159,7 +159,7 @@ func (m *Model) FindOneAndDelete(ctx context.Context, v, filter interface{}, } // FindOneAndReplace finds a single document and replaces it. -func (m *Model) FindOneAndReplace(ctx context.Context, v, filter interface{}, replacement interface{}, +func (m *Model) FindOneAndReplace(ctx context.Context, v, filter, replacement interface{}, opts ...*mopt.FindOneAndReplaceOptions) error { res, err := m.Collection.FindOneAndReplace(ctx, filter, replacement, opts...) if err != nil { @@ -170,7 +170,7 @@ func (m *Model) FindOneAndReplace(ctx context.Context, v, filter interface{}, re } // FindOneAndUpdate finds a single document and updates it. -func (m *Model) FindOneAndUpdate(ctx context.Context, v, filter interface{}, update interface{}, +func (m *Model) FindOneAndUpdate(ctx context.Context, v, filter, update interface{}, opts ...*mopt.FindOneAndUpdateOptions) error { res, err := m.Collection.FindOneAndUpdate(ctx, filter, update, opts...) if err != nil { diff --git a/core/stores/monc/cachedmodel.go b/core/stores/monc/cachedmodel.go index 93d27694c225..7c1eeb84a3e0 100644 --- a/core/stores/monc/cachedmodel.go +++ b/core/stores/monc/cachedmodel.go @@ -192,7 +192,7 @@ func (mm *Model) InsertOneNoCache(ctx context.Context, document interface{}, } // ReplaceOne replaces a single document in the collection, and remove the cache. -func (mm *Model) ReplaceOne(ctx context.Context, key string, filter interface{}, replacement interface{}, +func (mm *Model) ReplaceOne(ctx context.Context, key string, filter, replacement interface{}, opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error) { res, err := mm.Model.ReplaceOne(ctx, filter, replacement, opts...) if err != nil { @@ -207,7 +207,7 @@ func (mm *Model) ReplaceOne(ctx context.Context, key string, filter interface{}, } // ReplaceOneNoCache replaces a single document in the collection. -func (mm *Model) ReplaceOneNoCache(ctx context.Context, filter interface{}, replacement interface{}, +func (mm *Model) ReplaceOneNoCache(ctx context.Context, filter, replacement interface{}, opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error) { return mm.Model.ReplaceOne(ctx, filter, replacement, opts...) } @@ -218,7 +218,7 @@ func (mm *Model) SetCache(key string, v interface{}) error { } // UpdateByID updates the document with given id with update, and remove the cache. -func (mm *Model) UpdateByID(ctx context.Context, key string, id interface{}, update interface{}, +func (mm *Model) UpdateByID(ctx context.Context, key string, id, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) { res, err := mm.Model.UpdateByID(ctx, id, update, opts...) if err != nil { @@ -233,13 +233,13 @@ func (mm *Model) UpdateByID(ctx context.Context, key string, id interface{}, upd } // UpdateByIDNoCache updates the document with given id with update. -func (mm *Model) UpdateByIDNoCache(ctx context.Context, id interface{}, update interface{}, +func (mm *Model) UpdateByIDNoCache(ctx context.Context, id, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) { return mm.Model.UpdateByID(ctx, id, update, opts...) } // UpdateMany updates the documents that match filter with update, and remove the cache. -func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter interface{}, update interface{}, +func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) { res, err := mm.Model.UpdateMany(ctx, filter, update, opts...) if err != nil { @@ -254,13 +254,13 @@ func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter interface } // UpdateManyNoCache updates the documents that match filter with update. -func (mm *Model) UpdateManyNoCache(ctx context.Context, filter interface{}, update interface{}, +func (mm *Model) UpdateManyNoCache(ctx context.Context, filter, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) { return mm.Model.UpdateMany(ctx, filter, update, opts...) } // UpdateOne updates the first document that matches filter with update, and remove the cache. -func (mm *Model) UpdateOne(ctx context.Context, key string, filter interface{}, update interface{}, +func (mm *Model) UpdateOne(ctx context.Context, key string, filter, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) { res, err := mm.Model.UpdateOne(ctx, filter, update, opts...) if err != nil { @@ -275,7 +275,7 @@ func (mm *Model) UpdateOne(ctx context.Context, key string, filter interface{}, } // UpdateOneNoCache updates the first document that matches filter with update. -func (mm *Model) UpdateOneNoCache(ctx context.Context, filter interface{}, update interface{}, +func (mm *Model) UpdateOneNoCache(ctx context.Context, filter, update interface{}, opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) { return mm.Model.UpdateOne(ctx, filter, update, opts...) } diff --git a/tools/goctl/api/docgen/doc.go b/tools/goctl/api/docgen/doc.go index c4b0cbeda27c..37e21e7e6cf6 100644 --- a/tools/goctl/api/docgen/doc.go +++ b/tools/goctl/api/docgen/doc.go @@ -107,7 +107,7 @@ func associatedTypes(tp spec.DefineStruct, tps *[]spec.Type) { } // buildTypes gen types to string -func buildTypes(types []spec.Type, all []spec.Type) (string, error) { +func buildTypes(types, all []spec.Type) (string, error) { var builder strings.Builder first := true for _, tp := range types {