Skip to content
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
10 changes: 5 additions & 5 deletions bson/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ var nestedInstance = nestedtest1{
const extendedBSONDir = "../testdata/extended_bson"

var (
extJSONFiles map[string]map[string]interface{}
extJSONFiles map[string]map[string]any
extJSONFilesMu sync.Mutex
)

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

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

if extJSONFiles == nil {
extJSONFiles = make(map[string]map[string]interface{})
extJSONFiles = make(map[string]map[string]any)
}
extJSONFiles[filename] = v
return v
Expand Down
24 changes: 12 additions & 12 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func TestD_MarshalJSON(t *testing.T) {
testcases := []struct {
name string
test D
expected interface{}
expected any
}{
{
"nil",
Expand All @@ -329,21 +329,21 @@ func TestD_MarshalJSON(t *testing.T) {
{"g", D{{"foo", "bar"}}},
},
struct {
A int `json:"a"`
B bool `json:"b"`
C string `json:"c"`
D interface{} `json:"d"`
E float32 `json:"e"`
F []interface{} `json:"f"`
G map[string]interface{} `json:"g"`
A int `json:"a"`
B bool `json:"b"`
C string `json:"c"`
D any `json:"d"`
E float32 `json:"e"`
F []any `json:"f"`
G map[string]any `json:"g"`
}{
A: 42,
B: true,
C: "answer",
D: nil,
E: 2.71828,
F: []interface{}{42, true, "answer", nil, 2.71828},
G: map[string]interface{}{"foo": "bar"},
F: []any{42, true, "answer", nil, 2.71828},
G: map[string]any{"foo": "bar"},
},
},
}
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestD_UnmarshalJSON(t *testing.T) {
{"pi", 3.142},
{"boolean", true},
{"nothing", nil},
{"list", []interface{}{"hello world", 3.142, false, nil, D{{"Lorem", "ipsum"}}}},
{"list", []any{"hello world", 3.142, false, nil, D{{"Lorem", "ipsum"}}}},
{"document", D{{"foo", "bar"}}},
},
},
Expand Down Expand Up @@ -453,7 +453,7 @@ func TestD_UnmarshalJSON(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

var a map[string]interface{}
var a map[string]any
want := json.Unmarshal([]byte(tc.test), &a)
var b D
got := json.Unmarshal([]byte(tc.test), &b)
Expand Down
2 changes: 1 addition & 1 deletion bson/bsoncodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type DecodeContext struct {
truncate bool

// defaultDocumentType specifies the Go type to decode top-level and nested BSON documents into. In particular, the
// usage for this field is restricted to data typed as "interface{}" or "map[string]interface{}". If DocumentType is
// usage for this field is restricted to data typed as "any" or "map[string]any". If DocumentType is
// set to a type that a BSON document cannot be unmarshaled into (e.g. "string"), unmarshalling will result in an
// error.
defaultDocumentType reflect.Type
Expand Down
6 changes: 3 additions & 3 deletions bson/bsoncodec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func ExampleValueDecoder() {

type llCodec struct {
t *testing.T
decodeval interface{}
encodeval interface{}
decodeval any
encodeval any
err error
}

func (llc *llCodec) EncodeValue(_ EncodeContext, _ ValueWriter, i interface{}) error {
func (llc *llCodec) EncodeValue(_ EncodeContext, _ ValueWriter, i any) error {
if llc.err != nil {
return llc.err
}
Expand Down
2 changes: 1 addition & 1 deletion bson/bsonrw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (i invoked) String() string {
type valueReaderWriter struct {
T *testing.T
invoked invoked
Return interface{} // Can be a primitive or a bsoncore.Value
Return any // Can be a primitive or a bsoncore.Value
BSONType Type
Err error
ErrAfter invoked // error after this method is called
Expand Down
4 changes: 2 additions & 2 deletions bson/codec_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *typeEncoderCache) LoadOrStore(rt reflect.Type, enc ValueEncoder) ValueE

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

func (c *typeDecoderCache) Clone() *typeDecoderCache {
cc := new(typeDecoderCache)
c.cache.Range(func(k, v interface{}) bool {
c.cache.Range(func(k, v any) bool {
if k != nil && v != nil {
cc.cache.Store(k, v)
}
Expand Down
4 changes: 2 additions & 2 deletions bson/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (d *Decimal128) UnmarshalJSON(b []byte) error {
return nil
}

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

// Extended JSON
if !ok {
m, ok := res.(map[string]interface{})
m, ok := res.(map[string]any)
if !ok {
return errors.New("not an extended JSON Decimal128: expected document")
}
Expand Down
6 changes: 3 additions & 3 deletions bson/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var ErrDecodeToNil = errors.New("cannot Decode to nil value")
// methods and is not consumable from outside of this package. The Decoders retrieved from this pool
// must have both Reset and SetRegistry called on them.
var decPool = sync.Pool{
New: func() interface{} {
New: func() any {
return new(Decoder)
},
}
Expand All @@ -44,7 +44,7 @@ func NewDecoder(vr ValueReader) *Decoder {
// value pointed to by val.
//
// See [Unmarshal] for details about BSON unmarshaling behavior.
func (d *Decoder) Decode(val interface{}) error {
func (d *Decoder) Decode(val any) error {
if unmarshaler, ok := val.(Unmarshaler); ok {
// TODO(skriptble): Reuse a []byte here and use the AppendDocumentBytes method.
buf, err := copyDocumentToBytes(d.vr)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (d *Decoder) SetRegistry(r *Registry) {
}

// DefaultDocumentM causes the Decoder to always unmarshal documents into the bson.M type. This
// behavior is restricted to data typed as "interface{}" or "map[string]interface{}".
// behavior is restricted to data typed as "any" or "map[string]any".
func (d *Decoder) DefaultDocumentM() {
d.dc.defaultDocumentType = reflect.TypeOf(M{})
}
Expand Down
4 changes: 2 additions & 2 deletions bson/decoder_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func ExampleDecoder_DefaultDocumentM() {
decoder := bson.NewDecoder(bson.NewDocumentReader(bytes.NewReader(data)))

type City struct {
Name string `bson:"name"`
Properties interface{} `bson:"properties"`
Name string `bson:"name"`
Properties any `bson:"properties"`
}

// Configure the Decoder to default to decoding BSON documents as the M
Expand Down
Loading
Loading