Skip to content

Commit 6b8a2e7

Browse files
Merge branch 'mongodb:master' into GODRIVER-3599/sbom_generation_using_cyclonedx-gomod
2 parents 2ca839d + 184e7b2 commit 6b8a2e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+348
-348
lines changed

bson/benchmark_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ var nestedInstance = nestedtest1{
147147
const extendedBSONDir = "../testdata/extended_bson"
148148

149149
var (
150-
extJSONFiles map[string]map[string]interface{}
150+
extJSONFiles map[string]map[string]any
151151
extJSONFilesMu sync.Mutex
152152
)
153153

154154
// readExtJSONFile reads the GZIP-compressed extended JSON document from the given filename in the
155155
// "extended BSON" test data directory (../testdata/extended_bson) and returns it as a
156-
// map[string]interface{}. It panics on any errors.
157-
func readExtJSONFile(filename string) map[string]interface{} {
156+
// map[string]any. It panics on any errors.
157+
func readExtJSONFile(filename string) map[string]any {
158158
extJSONFilesMu.Lock()
159159
defer extJSONFilesMu.Unlock()
160160
if v, ok := extJSONFiles[filename]; ok {
@@ -182,14 +182,14 @@ func readExtJSONFile(filename string) map[string]interface{} {
182182
panic(fmt.Sprintf("error reading GZIP contents of file: %s", err))
183183
}
184184

185-
var v map[string]interface{}
185+
var v map[string]any
186186
err = UnmarshalExtJSON(data, false, &v)
187187
if err != nil {
188188
panic(fmt.Sprintf("error unmarshalling extended JSON: %s", err))
189189
}
190190

191191
if extJSONFiles == nil {
192-
extJSONFiles = make(map[string]map[string]interface{})
192+
extJSONFiles = make(map[string]map[string]any)
193193
}
194194
extJSONFiles[filename] = v
195195
return v

bson/bson_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func TestD_MarshalJSON(t *testing.T) {
305305
testcases := []struct {
306306
name string
307307
test D
308-
expected interface{}
308+
expected any
309309
}{
310310
{
311311
"nil",
@@ -329,21 +329,21 @@ func TestD_MarshalJSON(t *testing.T) {
329329
{"g", D{{"foo", "bar"}}},
330330
},
331331
struct {
332-
A int `json:"a"`
333-
B bool `json:"b"`
334-
C string `json:"c"`
335-
D interface{} `json:"d"`
336-
E float32 `json:"e"`
337-
F []interface{} `json:"f"`
338-
G map[string]interface{} `json:"g"`
332+
A int `json:"a"`
333+
B bool `json:"b"`
334+
C string `json:"c"`
335+
D any `json:"d"`
336+
E float32 `json:"e"`
337+
F []any `json:"f"`
338+
G map[string]any `json:"g"`
339339
}{
340340
A: 42,
341341
B: true,
342342
C: "answer",
343343
D: nil,
344344
E: 2.71828,
345-
F: []interface{}{42, true, "answer", nil, 2.71828},
346-
G: map[string]interface{}{"foo": "bar"},
345+
F: []any{42, true, "answer", nil, 2.71828},
346+
G: map[string]any{"foo": "bar"},
347347
},
348348
},
349349
}
@@ -400,7 +400,7 @@ func TestD_UnmarshalJSON(t *testing.T) {
400400
{"pi", 3.142},
401401
{"boolean", true},
402402
{"nothing", nil},
403-
{"list", []interface{}{"hello world", 3.142, false, nil, D{{"Lorem", "ipsum"}}}},
403+
{"list", []any{"hello world", 3.142, false, nil, D{{"Lorem", "ipsum"}}}},
404404
{"document", D{{"foo", "bar"}}},
405405
},
406406
},
@@ -453,7 +453,7 @@ func TestD_UnmarshalJSON(t *testing.T) {
453453
t.Run(tc.name, func(t *testing.T) {
454454
t.Parallel()
455455

456-
var a map[string]interface{}
456+
var a map[string]any
457457
want := json.Unmarshal([]byte(tc.test), &a)
458458
var b D
459459
got := json.Unmarshal([]byte(tc.test), &b)

bson/bsoncodec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type DecodeContext struct {
107107
truncate bool
108108

109109
// defaultDocumentType specifies the Go type to decode top-level and nested BSON documents into. In particular, the
110-
// usage for this field is restricted to data typed as "interface{}" or "map[string]interface{}". If DocumentType is
110+
// usage for this field is restricted to data typed as "any" or "map[string]any". If DocumentType is
111111
// set to a type that a BSON document cannot be unmarshaled into (e.g. "string"), unmarshalling will result in an
112112
// error.
113113
defaultDocumentType reflect.Type

bson/bsoncodec_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func ExampleValueDecoder() {
4343

4444
type llCodec struct {
4545
t *testing.T
46-
decodeval interface{}
47-
encodeval interface{}
46+
decodeval any
47+
encodeval any
4848
err error
4949
}
5050

51-
func (llc *llCodec) EncodeValue(_ EncodeContext, _ ValueWriter, i interface{}) error {
51+
func (llc *llCodec) EncodeValue(_ EncodeContext, _ ValueWriter, i any) error {
5252
if llc.err != nil {
5353
return llc.err
5454
}

bson/bsonrw_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (i invoked) String() string {
186186
type valueReaderWriter struct {
187187
T *testing.T
188188
invoked invoked
189-
Return interface{} // Can be a primitive or a bsoncore.Value
189+
Return any // Can be a primitive or a bsoncore.Value
190190
BSONType Type
191191
Err error
192192
ErrAfter invoked // error after this method is called

bson/codec_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (c *typeEncoderCache) LoadOrStore(rt reflect.Type, enc ValueEncoder) ValueE
4949

5050
func (c *typeEncoderCache) Clone() *typeEncoderCache {
5151
cc := new(typeEncoderCache)
52-
c.cache.Range(func(k, v interface{}) bool {
52+
c.cache.Range(func(k, v any) bool {
5353
if k != nil && v != nil {
5454
cc.cache.Store(k, v)
5555
}
@@ -82,7 +82,7 @@ func (c *typeDecoderCache) LoadOrStore(rt reflect.Type, dec ValueDecoder) ValueD
8282

8383
func (c *typeDecoderCache) Clone() *typeDecoderCache {
8484
cc := new(typeDecoderCache)
85-
c.cache.Range(func(k, v interface{}) bool {
85+
c.cache.Range(func(k, v any) bool {
8686
if k != nil && v != nil {
8787
cc.cache.Store(k, v)
8888
}

bson/decimal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (d *Decimal128) UnmarshalJSON(b []byte) error {
145145
return nil
146146
}
147147

148-
var res interface{}
148+
var res any
149149
err := json.Unmarshal(b, &res)
150150
if err != nil {
151151
return err
@@ -154,7 +154,7 @@ func (d *Decimal128) UnmarshalJSON(b []byte) error {
154154

155155
// Extended JSON
156156
if !ok {
157-
m, ok := res.(map[string]interface{})
157+
m, ok := res.(map[string]any)
158158
if !ok {
159159
return errors.New("not an extended JSON Decimal128: expected document")
160160
}

bson/decoder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var ErrDecodeToNil = errors.New("cannot Decode to nil value")
2020
// methods and is not consumable from outside of this package. The Decoders retrieved from this pool
2121
// must have both Reset and SetRegistry called on them.
2222
var decPool = sync.Pool{
23-
New: func() interface{} {
23+
New: func() any {
2424
return new(Decoder)
2525
},
2626
}
@@ -44,7 +44,7 @@ func NewDecoder(vr ValueReader) *Decoder {
4444
// value pointed to by val.
4545
//
4646
// See [Unmarshal] for details about BSON unmarshaling behavior.
47-
func (d *Decoder) Decode(val interface{}) error {
47+
func (d *Decoder) Decode(val any) error {
4848
if unmarshaler, ok := val.(Unmarshaler); ok {
4949
// TODO(skriptble): Reuse a []byte here and use the AppendDocumentBytes method.
5050
buf, err := copyDocumentToBytes(d.vr)
@@ -88,7 +88,7 @@ func (d *Decoder) SetRegistry(r *Registry) {
8888
}
8989

9090
// DefaultDocumentM causes the Decoder to always unmarshal documents into the bson.M type. This
91-
// behavior is restricted to data typed as "interface{}" or "map[string]interface{}".
91+
// behavior is restricted to data typed as "any" or "map[string]any".
9292
func (d *Decoder) DefaultDocumentM() {
9393
d.dc.defaultDocumentType = reflect.TypeOf(M{})
9494
}

bson/decoder_example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func ExampleDecoder_DefaultDocumentM() {
7070
decoder := bson.NewDecoder(bson.NewDocumentReader(bytes.NewReader(data)))
7171

7272
type City struct {
73-
Name string `bson:"name"`
74-
Properties interface{} `bson:"properties"`
73+
Name string `bson:"name"`
74+
Properties any `bson:"properties"`
7575
}
7676

7777
// Configure the Decoder to default to decoding BSON documents as the M

0 commit comments

Comments
 (0)