goext/mongoext/registry.go

29 lines
977 B
Go
Raw Normal View History

2023-05-05 17:47:30 +02:00
package mongoext
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"gogs.mikescher.com/BlackForestBytes/goext/rfctime"
"reflect"
)
func CreateGoExtBsonRegistry() *bsoncodec.Registry {
rb := bsoncodec.NewRegistryBuilder()
rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.RFC3339Time{}), rfctime.RFC3339Time{})
2023-05-05 18:05:58 +02:00
rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.RFC3339Time{}), rfctime.RFC3339Time{})
2023-05-05 18:00:25 +02:00
rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.RFC3339NanoTime{}), rfctime.RFC3339NanoTime{})
2023-05-05 18:05:58 +02:00
rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.RFC3339NanoTime{}), rfctime.RFC3339NanoTime{})
2023-05-05 17:47:30 +02:00
2023-06-10 19:13:15 +02:00
rb.RegisterTypeDecoder(reflect.TypeOf(rfctime.Date{}), rfctime.Date{})
rb.RegisterTypeDecoder(reflect.TypeOf(&rfctime.Date{}), rfctime.Date{})
2023-05-05 17:57:21 +02:00
bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb)
bsoncodec.DefaultValueDecoders{}.RegisterDefaultDecoders(rb)
2023-05-05 17:47:30 +02:00
2023-05-05 17:57:21 +02:00
bson.PrimitiveCodecs{}.RegisterPrimitiveCodecs(rb)
2023-05-05 17:47:30 +02:00
2023-05-05 17:57:21 +02:00
return rb.Build()
2023-05-05 17:47:30 +02:00
}