updated mongo driver dependencies to v2
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m27s
Build Docker and Deploy / Run goext test-suite (push) Failing after 1m27s
This commit is contained in:
+13
-44
@@ -4,11 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"reflect"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -83,8 +79,8 @@ func (t *Date) UnmarshalText(data []byte) error {
|
||||
return t.ParseString(string(data))
|
||||
}
|
||||
|
||||
func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
if bt == bsontype.Null {
|
||||
func (t *Date) UnmarshalBSONValue(bt byte, data []byte) error {
|
||||
if bson.Type(bt) == bson.TypeNull {
|
||||
// we can't set nil in UnmarshalBSONValue (so we use default(struct))
|
||||
// Use mongoext.CreateGoExtBsonRegistry if you need to unmarsh pointer values
|
||||
// https://stackoverflow.com/questions/75167597
|
||||
@@ -92,12 +88,12 @@ func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
*t = Date{}
|
||||
return nil
|
||||
}
|
||||
if bt != bsontype.String {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into Date", bt))
|
||||
if bson.Type(bt) != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into Date", bson.Type(bt)))
|
||||
}
|
||||
|
||||
var tt string
|
||||
err := bson.RawValue{Type: bt, Value: data}.Unmarshal(&tt)
|
||||
err := bson.RawValue{Type: bson.Type(bt), Value: data}.Unmarshal(&tt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,43 +116,16 @@ func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t Date) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
func (t Date) MarshalBSONValue() (byte, []byte, error) {
|
||||
var tp bson.Type
|
||||
var data []byte
|
||||
var err error
|
||||
if t.IsZero() {
|
||||
return bson.MarshalValue("")
|
||||
}
|
||||
return bson.MarshalValue(t.String())
|
||||
}
|
||||
|
||||
func (t Date) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if val.Kind() == reflect.Pointer && val.IsNil() {
|
||||
if !val.CanSet() {
|
||||
return errors.New("ValueUnmarshalerDecodeValue")
|
||||
}
|
||||
val.Set(reflect.New(val.Type().Elem()))
|
||||
}
|
||||
|
||||
tp, src, err := bsonrw.Copier{}.CopyValueToBytes(vr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Pointer && len(src) == 0 {
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
err = t.UnmarshalBSONValue(tp, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Pointer {
|
||||
val.Set(reflect.ValueOf(&t))
|
||||
tp, data, err = bson.MarshalValue("")
|
||||
} else {
|
||||
val.Set(reflect.ValueOf(t))
|
||||
tp, data, err = bson.MarshalValue(t.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
return byte(tp), data, err
|
||||
}
|
||||
|
||||
func (t Date) Serialize() string {
|
||||
|
||||
Reference in New Issue
Block a user