From dad0e3240d8bcb4b03bbe84c46d04ea9b9140e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 26 Apr 2026 14:53:24 +0200 Subject: [PATCH] v0.0.636 Remove remaining traces of v1 mongo driver --- go.mod | 1 - go.sum | 2 -- goextVersion.go | 4 ++-- rfctime/unix.go | 54 ++++++++------------------------------------ rfctime/unixMilli.go | 54 ++++++++------------------------------------ rfctime/unixNano.go | 54 ++++++++------------------------------------ 6 files changed, 32 insertions(+), 137 deletions(-) diff --git a/go.mod b/go.mod index 5c86502..7951ff7 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,6 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/jung-kurt/gofpdf v1.16.2 github.com/xuri/excelize/v2 v2.10.1 - go.mongodb.org/mongo-driver v1.17.9 golang.org/x/sync v0.20.0 ) diff --git a/go.sum b/go.sum index 869c951..c78e473 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,6 @@ github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/T github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.17.9 h1:IexDdCuuNJ3BHrELgBlyaH9p60JXAvdzWR128q+U5tU= -go.mongodb.org/mongo-driver v1.17.9/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= go.mongodb.org/mongo-driver/v2 v2.5.1 h1:j2U/Qp+wvueSpqitLCSZPT/+ZpVc1xzuwdHWwl7d8ro= go.mongodb.org/mongo-driver/v2 v2.5.1/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= diff --git a/goextVersion.go b/goextVersion.go index 2a28d22..0847a3f 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.635" +const GoextVersion = "0.0.636" -const GoextVersionTimestamp = "2026-04-26T14:47:05+0200" +const GoextVersionTimestamp = "2026-04-26T14:53:24+0200" diff --git a/rfctime/unix.go b/rfctime/unix.go index 87a39e1..c579013 100644 --- a/rfctime/unix.go +++ b/rfctime/unix.go @@ -4,13 +4,10 @@ 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" "strconv" "time" + + "go.mongodb.org/mongo-driver/v2/bson" ) type UnixTime time.Time @@ -66,8 +63,8 @@ func (t *UnixTime) UnmarshalText(data []byte) error { return nil } -func (t *UnixTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { - if bt == bson.TypeNull { +func (t *UnixTime) 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 @@ -75,11 +72,11 @@ func (t *UnixTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { *t = UnixTime{} return nil } - if bt != bson.TypeDateTime { - return errors.New(fmt.Sprintf("cannot unmarshal %v into UnixTime", bt)) + if bson.Type(bt) != bson.TypeDateTime { + return errors.New(fmt.Sprintf("cannot unmarshal %v into UnixTime", bson.Type(bt))) } var tt time.Time - 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 } @@ -87,40 +84,9 @@ func (t *UnixTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { return nil } -func (t UnixTime) MarshalBSONValue() (bsontype.Type, []byte, error) { - return bson.MarshalValue(time.Time(t)) -} - -func (t UnixTime) 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)) - } else { - val.Set(reflect.ValueOf(t)) - } - - return nil +func (t UnixTime) MarshalBSONValue() (byte, []byte, error) { + tp, data, err := bson.MarshalValue(time.Time(t)) + return byte(tp), data, err } func (t UnixTime) Serialize() string { diff --git a/rfctime/unixMilli.go b/rfctime/unixMilli.go index d496103..9900145 100644 --- a/rfctime/unixMilli.go +++ b/rfctime/unixMilli.go @@ -4,13 +4,10 @@ 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" "strconv" "time" + + "go.mongodb.org/mongo-driver/v2/bson" ) type UnixMilliTime time.Time @@ -66,8 +63,8 @@ func (t *UnixMilliTime) UnmarshalText(data []byte) error { return nil } -func (t *UnixMilliTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { - if bt == bson.TypeNull { +func (t *UnixMilliTime) 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 @@ -75,11 +72,11 @@ func (t *UnixMilliTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error *t = UnixMilliTime{} return nil } - if bt != bson.TypeDateTime { - return errors.New(fmt.Sprintf("cannot unmarshal %v into UnixMilliTime", bt)) + if bson.Type(bt) != bson.TypeDateTime { + return errors.New(fmt.Sprintf("cannot unmarshal %v into UnixMilliTime", bson.Type(bt))) } var tt time.Time - 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 } @@ -87,40 +84,9 @@ func (t *UnixMilliTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error return nil } -func (t UnixMilliTime) MarshalBSONValue() (bsontype.Type, []byte, error) { - return bson.MarshalValue(time.Time(t)) -} - -func (t UnixMilliTime) 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)) - } else { - val.Set(reflect.ValueOf(t)) - } - - return nil +func (t UnixMilliTime) MarshalBSONValue() (byte, []byte, error) { + tp, data, err := bson.MarshalValue(time.Time(t)) + return byte(tp), data, err } func (t UnixMilliTime) Serialize() string { diff --git a/rfctime/unixNano.go b/rfctime/unixNano.go index 1ad945d..b392b73 100644 --- a/rfctime/unixNano.go +++ b/rfctime/unixNano.go @@ -4,13 +4,10 @@ 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" "strconv" "time" + + "go.mongodb.org/mongo-driver/v2/bson" ) type UnixNanoTime time.Time @@ -66,8 +63,8 @@ func (t *UnixNanoTime) UnmarshalText(data []byte) error { return nil } -func (t *UnixNanoTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { - if bt == bson.TypeNull { +func (t *UnixNanoTime) 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 @@ -75,11 +72,11 @@ func (t *UnixNanoTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { *t = UnixNanoTime{} return nil } - if bt != bson.TypeDateTime { - return errors.New(fmt.Sprintf("cannot unmarshal %v into UnixNanoTime", bt)) + if bson.Type(bt) != bson.TypeDateTime { + return errors.New(fmt.Sprintf("cannot unmarshal %v into UnixNanoTime", bson.Type(bt))) } var tt time.Time - 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 } @@ -87,40 +84,9 @@ func (t *UnixNanoTime) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { return nil } -func (t UnixNanoTime) MarshalBSONValue() (bsontype.Type, []byte, error) { - return bson.MarshalValue(time.Time(t)) -} - -func (t UnixNanoTime) 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)) - } else { - val.Set(reflect.ValueOf(t)) - } - - return nil +func (t UnixNanoTime) MarshalBSONValue() (byte, []byte, error) { + tp, data, err := bson.MarshalValue(time.Time(t)) + return byte(tp), data, err } func (t UnixNanoTime) Serialize() string {