updated mongo driver dependencies to v2
# Conflicts: # exerr/constructor.go # exerr/dataCategory.go # exerr/dataSeverity.go # exerr/dataType.go # exerr/exerr.go # go.mod # mongoext/registry.go # reflectext/primStrSer.go # rfctime/date.go # rfctime/rfc3339.go # rfctime/rfc3339Nano.go # rfctime/seconds.go # rfctime/unix.go # rfctime/unixMilli.go # rfctime/unixNano.go # wmo/collection.go # wmo/queryInsert.go
This commit is contained in:
+35
-71
@@ -4,14 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/dataext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"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"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type ErrorType struct {
|
||||
@@ -21,42 +16,42 @@ type ErrorType struct {
|
||||
|
||||
//goland:noinspection GoUnusedGlobalVariable
|
||||
var (
|
||||
TypeInternal = NewType("INTERNAL_ERROR", langext.Ptr(500))
|
||||
TypePanic = NewType("PANIC", langext.Ptr(500))
|
||||
TypeNotImplemented = NewType("NOT_IMPLEMENTED", langext.Ptr(500))
|
||||
TypeAssert = NewType("ASSERT", langext.Ptr(500))
|
||||
TypeInternal = NewType("INTERNAL_ERROR", new(500))
|
||||
TypePanic = NewType("PANIC", new(500))
|
||||
TypeNotImplemented = NewType("NOT_IMPLEMENTED", new(500))
|
||||
TypeAssert = NewType("ASSERT", new(500))
|
||||
|
||||
TypeMongoQuery = NewType("MONGO_QUERY", langext.Ptr(500))
|
||||
TypeCursorTokenDecode = NewType("CURSOR_TOKEN_DECODE", langext.Ptr(500))
|
||||
TypeMongoFilter = NewType("MONGO_FILTER", langext.Ptr(500))
|
||||
TypeMongoReflection = NewType("MONGO_REFLECTION", langext.Ptr(500))
|
||||
TypeMongoInvalidOpt = NewType("MONGO_INVALIDOPT", langext.Ptr(500))
|
||||
TypeMongoQuery = NewType("MONGO_QUERY", new(500))
|
||||
TypeCursorTokenDecode = NewType("CURSOR_TOKEN_DECODE", new(500))
|
||||
TypeMongoFilter = NewType("MONGO_FILTER", new(500))
|
||||
TypeMongoReflection = NewType("MONGO_REFLECTION", new(500))
|
||||
TypeMongoInvalidOpt = NewType("MONGO_INVALIDOPT", new(500))
|
||||
|
||||
TypeSQLQuery = NewType("SQL_QUERY", langext.Ptr(500))
|
||||
TypeSQLBuild = NewType("SQL_BUILD", langext.Ptr(500))
|
||||
TypeSQLDecode = NewType("SQL_DECODE", langext.Ptr(500))
|
||||
TypeSQLQuery = NewType("SQL_QUERY", new(500))
|
||||
TypeSQLBuild = NewType("SQL_BUILD", new(500))
|
||||
TypeSQLDecode = NewType("SQL_DECODE", new(500))
|
||||
|
||||
TypeWrap = NewType("Wrap", nil)
|
||||
|
||||
TypeBindFailURI = NewType("BINDFAIL_URI", langext.Ptr(400))
|
||||
TypeBindFailQuery = NewType("BINDFAIL_QUERY", langext.Ptr(400))
|
||||
TypeBindFailJSON = NewType("BINDFAIL_JSON", langext.Ptr(400))
|
||||
TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", langext.Ptr(400))
|
||||
TypeBindFailHeader = NewType("BINDFAIL_HEADER", langext.Ptr(400))
|
||||
TypeBindFailURI = NewType("BINDFAIL_URI", new(400))
|
||||
TypeBindFailQuery = NewType("BINDFAIL_QUERY", new(400))
|
||||
TypeBindFailJSON = NewType("BINDFAIL_JSON", new(400))
|
||||
TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", new(400))
|
||||
TypeBindFailHeader = NewType("BINDFAIL_HEADER", new(400))
|
||||
|
||||
TypeMarshalEntityID = NewType("MARSHAL_ENTITY_ID", langext.Ptr(400))
|
||||
TypeInvalidCSID = NewType("INVALID_CSID", langext.Ptr(400))
|
||||
TypeMarshalEntityID = NewType("MARSHAL_ENTITY_ID", new(400))
|
||||
TypeInvalidCSID = NewType("INVALID_CSID", new(400))
|
||||
|
||||
TypeGoogleStatuscode = NewType("GOOGLE_STATUSCODE", langext.Ptr(400))
|
||||
TypeGoogleResponse = NewType("GOOGLE_RESPONSE", langext.Ptr(400))
|
||||
TypeGoogleStatuscode = NewType("GOOGLE_STATUSCODE", new(400))
|
||||
TypeGoogleResponse = NewType("GOOGLE_RESPONSE", new(400))
|
||||
|
||||
TypeUnauthorized = NewType("UNAUTHORIZED", langext.Ptr(401))
|
||||
TypeAuthFailed = NewType("AUTH_FAILED", langext.Ptr(401))
|
||||
TypeUnauthorized = NewType("UNAUTHORIZED", new(401))
|
||||
TypeAuthFailed = NewType("AUTH_FAILED", new(401))
|
||||
|
||||
TypeInvalidImage = NewType("IMAGEEXT_INVALID_IMAGE", langext.Ptr(400))
|
||||
TypeInvalidMimeType = NewType("IMAGEEXT_INVALID_MIMETYPE", langext.Ptr(400))
|
||||
TypeInvalidImage = NewType("IMAGEEXT_INVALID_IMAGE", new(400))
|
||||
TypeInvalidMimeType = NewType("IMAGEEXT_INVALID_MIMETYPE", new(400))
|
||||
|
||||
TypeWebsocket = NewType("WEBSOCKET", langext.Ptr(500))
|
||||
TypeWebsocket = NewType("WEBSOCKET", new(500))
|
||||
|
||||
// other values come from the downstream application that uses goext
|
||||
)
|
||||
@@ -81,8 +76,8 @@ func (e ErrorType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(e.Key)
|
||||
}
|
||||
|
||||
func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
if bt == bson.TypeNull {
|
||||
func (e *ErrorType) 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
|
||||
@@ -90,11 +85,11 @@ func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
*e = ErrorType{}
|
||||
return nil
|
||||
}
|
||||
if bt != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bt))
|
||||
if bson.Type(bt) != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", 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
|
||||
}
|
||||
@@ -108,40 +103,9 @@ func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (e ErrorType) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
return bson.MarshalValue(e.Key)
|
||||
}
|
||||
|
||||
func (e ErrorType) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if val.Kind() == reflect.Ptr && 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.Ptr && len(src) == 0 {
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
err = e.UnmarshalBSONValue(tp, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val.Set(reflect.ValueOf(&e))
|
||||
} else {
|
||||
val.Set(reflect.ValueOf(e))
|
||||
}
|
||||
|
||||
return nil
|
||||
func (e ErrorType) MarshalBSONValue() (byte, []byte, error) {
|
||||
tp, data, err := bson.MarshalValue(e.Key)
|
||||
return byte(tp), data, err
|
||||
}
|
||||
|
||||
var registeredTypes = dataext.SyncMap[string, ErrorType]{}
|
||||
|
||||
Reference in New Issue
Block a user