Skip to content

Commit 1950917

Browse files
authored
Replace all uses of 'interface{}' with 'any' in the internal/ packages. (#2140)
1 parent 8ad29f8 commit 1950917

File tree

16 files changed

+70
-70
lines changed

16 files changed

+70
-70
lines changed

internal/bsonutil/bsonutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func RawArrayToDocuments(arr bson.RawArray) []bson.Raw {
5252
return out
5353
}
5454

55-
// RawToInterfaces takes one or many bson.Raw documents and returns them as a []interface{}.
56-
func RawToInterfaces(docs ...bson.Raw) []interface{} {
57-
out := make([]interface{}, len(docs))
55+
// RawToInterfaces takes one or many bson.Raw documents and returns them as a []any.
56+
func RawToInterfaces(docs ...bson.Raw) []any {
57+
out := make([]any, len(docs))
5858
for i := range docs {
5959
out[i] = docs[i]
6060
}

internal/cmd/benchmark/benchmark_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ type poplarTestArtifact struct {
663663
// poplarTestMetrics was copied from
664664
// https://github.com/evergreen-ci/poplar/blob/8d03d2bacde0897cedd73ed79ddc167ed1ed4c77/report.go#L124
665665
type poplarTestMetrics struct {
666-
Name string `bson:"name" json:"name" yaml:"name"`
667-
Version int `bson:"version,omitempty" json:"version,omitempty" yaml:"version,omitempty"`
668-
Type string `bson:"type" json:"type" yaml:"type"`
669-
Value interface{} `bson:"value" json:"value" yaml:"value"`
666+
Name string `bson:"name" json:"name" yaml:"name"`
667+
Version int `bson:"version,omitempty" json:"version,omitempty" yaml:"version,omitempty"`
668+
Type string `bson:"type" json:"type" yaml:"type"`
669+
Value any `bson:"value" json:"value" yaml:"value"`
670670
}

internal/cmd/testkms/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func main() {
8888
}
8989
defer func() { _ = keyVaultClient.Disconnect(context.Background()) }()
9090

91-
kmsProvidersMap := map[string]map[string]interface{}{
91+
kmsProvidersMap := map[string]map[string]any{
9292
provider: {},
9393
}
9494
ceOpts := options.ClientEncryption().SetKmsProviders(kmsProvidersMap).SetKeyVaultNamespace("keyvault.datakeys")

internal/codecutil/encoding.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var ErrNilValue = errors.New("value is nil")
2222
// MarshalError is returned when attempting to transform a value into a document
2323
// results in an error.
2424
type MarshalError struct {
25-
Value interface{}
25+
Value any
2626
Err error
2727
}
2828

@@ -39,7 +39,7 @@ type EncoderFn func(io.Writer) *bson.Encoder
3939

4040
// MarshalValue will attempt to encode the value with the encoder returned by
4141
// the encoder function.
42-
func MarshalValue(val interface{}, encFn EncoderFn) (bsoncore.Value, error) {
42+
func MarshalValue(val any, encFn EncoderFn) (bsoncore.Value, error) {
4343
// If the val is already a bsoncore.Value, then do nothing.
4444
if bval, ok := val.(bsoncore.Value); ok {
4545
return bval, nil

internal/codecutil/encoding_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestMarshalValue(t *testing.T) {
2828

2929
tests := []struct {
3030
name string
31-
val interface{}
31+
val any
3232
registry *bson.Registry
3333
encFn EncoderFn
3434
want string
@@ -49,7 +49,7 @@ func TestMarshalValue(t *testing.T) {
4949
},
5050
{
5151
name: "map",
52-
val: map[string]interface{}{"foo": "bar"},
52+
val: map[string]any{"foo": "bar"},
5353
want: `{"foo": "bar"}`,
5454
encFn: testEncFn(t),
5555
},

internal/csot/csot_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,55 +157,55 @@ func TestWithTimeout(t *testing.T) {
157157
timeout *time.Duration
158158
wantTimeout time.Duration
159159
wantDeadline bool
160-
wantValues []interface{}
160+
wantValues []any
161161
}{
162162
{
163163
name: "deadline set with non-zero timeout",
164164
parent: newTestContext(t, 1),
165165
timeout: ptrutil.Ptr(time.Duration(2)),
166166
wantTimeout: 1,
167167
wantDeadline: true,
168-
wantValues: []interface{}{},
168+
wantValues: []any{},
169169
},
170170
{
171171
name: "deadline set with zero timeout",
172172
parent: newTestContext(t, 1),
173173
timeout: ptrutil.Ptr(time.Duration(0)),
174174
wantTimeout: 1,
175175
wantDeadline: true,
176-
wantValues: []interface{}{},
176+
wantValues: []any{},
177177
},
178178
{
179179
name: "deadline set with nil timeout",
180180
parent: newTestContext(t, 1),
181181
timeout: nil,
182182
wantTimeout: 1,
183183
wantDeadline: true,
184-
wantValues: []interface{}{},
184+
wantValues: []any{},
185185
},
186186
{
187187
name: "deadline unset with non-zero timeout",
188188
parent: context.Background(),
189189
timeout: ptrutil.Ptr(time.Duration(1)),
190190
wantTimeout: 1,
191191
wantDeadline: true,
192-
wantValues: []interface{}{},
192+
wantValues: []any{},
193193
},
194194
{
195195
name: "deadline unset with zero timeout",
196196
parent: context.Background(),
197197
timeout: ptrutil.Ptr(time.Duration(0)),
198198
wantTimeout: 0,
199199
wantDeadline: false,
200-
wantValues: []interface{}{clientLevel{}},
200+
wantValues: []any{clientLevel{}},
201201
},
202202
{
203203
name: "deadline unset with nil timeout",
204204
parent: context.Background(),
205205
timeout: nil,
206206
wantTimeout: 0,
207207
wantDeadline: false,
208-
wantValues: []interface{}{},
208+
wantValues: []any{},
209209
},
210210
{
211211
// If "clientLevel" has been set, but a new timeout is applied
@@ -216,7 +216,7 @@ func TestWithTimeout(t *testing.T) {
216216
timeout: ptrutil.Ptr(time.Duration(1)),
217217
wantTimeout: 0,
218218
wantDeadline: false,
219-
wantValues: []interface{}{},
219+
wantValues: []any{},
220220
},
221221
}
222222

internal/docexamples/examples.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func InsertExamples(t *testing.T, db *mongo.Database) {
9898

9999
result, err := coll.InsertMany(
100100
context.TODO(),
101-
[]interface{}{
101+
[]any{
102102
bson.D{
103103
{"item", "journal"},
104104
{"qty", int32(25)},
@@ -149,7 +149,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) {
149149
{
150150
// Start Example 6
151151

152-
docs := []interface{}{
152+
docs := []any{
153153
bson.D{
154154
{"item", "journal"},
155155
{"qty", 25},
@@ -318,7 +318,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
318318
{
319319
// Start Example 14
320320

321-
docs := []interface{}{
321+
docs := []any{
322322
bson.D{
323323
{"item", "journal"},
324324
{"qty", 25},
@@ -480,7 +480,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) {
480480
{
481481
// Start Example 20
482482

483-
docs := []interface{}{
483+
docs := []any{
484484
bson.D{
485485
{"item", "journal"},
486486
{"qty", 25},
@@ -667,7 +667,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
667667
{
668668
// Start Example 29
669669

670-
docs := []interface{}{
670+
docs := []any{
671671
bson.D{
672672
{"item", "journal"},
673673
{"instock", bson.A{
@@ -897,7 +897,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
897897
{
898898
// Start Example 38
899899

900-
docs := []interface{}{
900+
docs := []any{
901901
bson.D{
902902
{"_id", 1},
903903
{"item", nil},
@@ -976,7 +976,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
976976
{
977977
// Start Example 42
978978

979-
docs := []interface{}{
979+
docs := []any{
980980
bson.D{
981981
{"item", "journal"},
982982
{"status", "A"},
@@ -1361,7 +1361,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
13611361
{
13621362
// Start Example 51
13631363

1364-
docs := []interface{}{
1364+
docs := []any{
13651365
bson.D{
13661366
{"item", "canvas"},
13671367
{"qty", 100},
@@ -1641,7 +1641,7 @@ func DeleteExamples(t *testing.T, db *mongo.Database) {
16411641

16421642
{
16431643
// Start Example 55
1644-
docs := []interface{}{
1644+
docs := []any{
16451645
bson.D{
16461646
{"item", "journal"},
16471647
{"qty", 25},
@@ -1985,7 +1985,7 @@ func WithTransactionExample(ctx context.Context) error {
19851985
barColl := client.Database("mydb1").Collection("bar", wcMajorityCollectionOpts)
19861986

19871987
// Step 1: Define the callback that specifies the sequence of operations to perform inside the transaction.
1988-
callback := func(sesctx context.Context) (interface{}, error) {
1988+
callback := func(sesctx context.Context) (any, error) {
19891989
// Important: You must pass sesctx as the Context parameter to the operations for them to be executed in the
19901990
// transaction.
19911991
if _, err := fooColl.InsertOne(sesctx, bson.D{{"abc", 1}}); err != nil {
@@ -2145,7 +2145,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) {
21452145
date20180205 := parseDate(t, "2018-02-05T06:03:00.000Z")
21462146
date20180111 := parseDate(t, "2018-01-11T07:15:00.000Z")
21472147

2148-
sales := []interface{}{
2148+
sales := []any{
21492149
bson.D{
21502150
{"date", date20180208},
21512151
{"items", bson.A{
@@ -2242,7 +2242,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) {
22422242
}},
22432243
},
22442244
}
2245-
airlines := []interface{}{
2245+
airlines := []any{
22462246
bson.D{
22472247
{"airline", 17},
22482248
{"name", "Air Canada"},
@@ -2314,7 +2314,7 @@ func AggregationExamples(t *testing.T, db *mongo.Database) {
23142314
{"base", "CYS"},
23152315
},
23162316
}
2317-
airAlliances := []interface{}{
2317+
airAlliances := []any{
23182318
bson.D{
23192319
{"name", "Star Alliance"},
23202320
{"airlines", bson.A{
@@ -2670,7 +2670,7 @@ func IndexExamples(t *testing.T, db *mongo.Database) {
26702670
err = restaurantsColl.Drop(ctx)
26712671
assert.NoError(t, err)
26722672

2673-
records := []interface{}{
2673+
records := []any{
26742674
bson.D{
26752675
{"student", "Marty McFly"},
26762676
{"classYear", 1986},
@@ -2691,7 +2691,7 @@ func IndexExamples(t *testing.T, db *mongo.Database) {
26912691
{"score", 99.9},
26922692
},
26932693
}
2694-
restaurants := []interface{}{
2694+
restaurants := []any{
26952695
bson.D{
26962696
{"name", "Chez Panisse"},
26972697
{"cuisine", "American/French"},
@@ -2884,7 +2884,7 @@ func StableAPIStrictCountExample(t *testing.T) {
28842884
// Start Versioned API Example 5
28852885

28862886
coll := client.Database("db").Collection("sales")
2887-
docs := []interface{}{
2887+
docs := []any{
28882888
bson.D{{"_id", 1}, {"item", "abc"}, {"price", 10}, {"quantity", 2}, {"date", "2021-01-01T08:00:00Z"}},
28892889
bson.D{{"_id", 2}, {"item", "jkl"}, {"price", 20}, {"quantity", 1}, {"date", "2021-02-03T09:00:00Z"}},
28902890
bson.D{{"_id", 3}, {"item", "xyz"}, {"price", 5}, {"quantity", 5}, {"date", "2021-02-03T09:05:00Z"}},
@@ -2938,7 +2938,7 @@ func StableAPIExamples() {
29382938

29392939
func insertSnapshotQueryTestData(mt *mtest.T) {
29402940
catColl := mt.CreateCollection(mtest.Collection{Name: "cats"}, true)
2941-
_, err := catColl.InsertMany(context.Background(), []interface{}{
2941+
_, err := catColl.InsertMany(context.Background(), []any{
29422942
bson.D{
29432943
{"adoptable", false},
29442944
{"name", "Miyagi"},
@@ -2955,7 +2955,7 @@ func insertSnapshotQueryTestData(mt *mtest.T) {
29552955
assert.NoError(mt, err)
29562956

29572957
dogColl := mt.CreateCollection(mtest.Collection{Name: "dogs"}, true)
2958-
_, err = dogColl.InsertMany(context.Background(), []interface{}{
2958+
_, err = dogColl.InsertMany(context.Background(), []any{
29592959
bson.D{
29602960
{"adoptable", true},
29612961
{"name", "Cormac"},
@@ -2972,7 +2972,7 @@ func insertSnapshotQueryTestData(mt *mtest.T) {
29722972
assert.NoError(mt, err)
29732973

29742974
salesColl := mt.CreateCollection(mtest.Collection{Name: "sales"}, true)
2975-
_, err = salesColl.InsertMany(context.Background(), []interface{}{
2975+
_, err = salesColl.InsertMany(context.Background(), []any{
29762976
bson.D{
29772977
{"shoeType", "hiking boot"},
29782978
{"price", 30.0},

internal/errutil/join.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (e *joinError) Is(target error) bool {
7777
}
7878

7979
// As calls [errors.As] with the first error in the slice.
80-
func (e *joinError) As(target interface{}) bool {
80+
func (e *joinError) As(target any) bool {
8181
if len(e.errs) == 0 {
8282
return false
8383
}

internal/errutil/join_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestJoin_ErrorsAs(t *testing.T) {
170170
tests := []struct {
171171
desc string
172172
errs []error
173-
target interface{}
173+
target any
174174
}{{
175175
desc: "one error with a matching target",
176176
errs: []error{err1},

internal/failpoint/failpoint.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ const (
2626
// https://github.com/mongodb/specifications/tree/HEAD/source/transactions/tests#server-fail-point
2727
type FailPoint struct {
2828
ConfigureFailPoint string `bson:"configureFailPoint"`
29-
// Mode should be a string, FailPointMode, or map[string]interface{}
30-
Mode interface{} `bson:"mode"`
31-
Data Data `bson:"data"`
29+
// Mode should be a string, FailPointMode, or map[string]any
30+
Mode any `bson:"mode"`
31+
Data Data `bson:"data"`
3232
}
3333

3434
// Mode configures when a fail point will be enabled. It is used to set the

0 commit comments

Comments
 (0)