diff --git a/_data/mongo.patch b/_data/mongo.patch new file mode 100644 index 0000000..909bc92 --- /dev/null +++ b/_data/mongo.patch @@ -0,0 +1,80 @@ +diff --git a/mongo/bson/bsoncodec/struct_codec.go b/mongo/bson/bsoncodec/struct_codec.go +--- a/mongo/bson/bsoncodec/struct_codec.go ++++ b/mongo/bson/bsoncodec/struct_codec.go +@@ -122,6 +122,10 @@ func (sc *StructCodec) EncodeValue(r EncodeContext, vw bsonrw.ValueWriter, val r + } + var rv reflect.Value + for _, desc := range sd.fl { ++ if desc.omitAlways { ++ continue ++ } ++ + if desc.inline == nil { + rv = val.Field(desc.idx) + } else { +@@ -400,15 +404,16 @@ type structDescription struct { + } + + type fieldDescription struct { +- name string // BSON key name +- fieldName string // struct field name +- idx int +- omitEmpty bool +- minSize bool +- truncate bool +- inline []int +- encoder ValueEncoder +- decoder ValueDecoder ++ name string // BSON key name ++ fieldName string // struct field name ++ idx int ++ omitEmpty bool ++ omitAlways bool ++ minSize bool ++ truncate bool ++ inline []int ++ encoder ValueEncoder ++ decoder ValueDecoder + } + + type byIndex []fieldDescription +@@ -491,6 +496,7 @@ func (sc *StructCodec) describeStruct(r *Registry, t reflect.Type) (*structDescr + } + description.name = stags.Name + description.omitEmpty = stags.OmitEmpty ++ description.omitAlways = stags.OmitAlways + description.minSize = stags.MinSize + description.truncate = stags.Truncate + +diff --git a/mongo/bson/bsoncodec/struct_tag_parser.go b/mongo/bson/bsoncodec/struct_tag_parser.go +--- a/mongo/bson/bsoncodec/struct_tag_parser.go ++++ b/mongo/bson/bsoncodec/struct_tag_parser.go +@@ -52,12 +52,13 @@ func (stpf StructTagParserFunc) ParseStructTags(sf reflect.StructField) (StructT + // + // TODO(skriptble): Add tags for undefined as nil and for null as nil. + type StructTags struct { +- Name string +- OmitEmpty bool +- MinSize bool +- Truncate bool +- Inline bool +- Skip bool ++ Name string ++ OmitEmpty bool ++ OmitAlways bool ++ MinSize bool ++ Truncate bool ++ Inline bool ++ Skip bool + } + + // DefaultStructTagParser is the StructTagParser used by the StructCodec by default. +@@ -108,6 +109,8 @@ func parseTags(key string, tag string) (StructTags, error) { + switch str { + case "omitempty": + st.OmitEmpty = true ++ case "omitalways": ++ st.OmitAlways = true + case "minsize": + st.MinSize = true + case "truncate": diff --git a/_data/update-mongo.sh b/_data/update-mongo.sh index b3f45f0..a4ff963 100755 --- a/_data/update-mongo.sh +++ b/_data/update-mongo.sh @@ -11,6 +11,10 @@ dir="/tmp/mongo_repo_$( uuidgen )" +echo "" +echo "> Clone https://github.dev/mongodb/mongo-go-driver" +echo "" + git clone "https://github.com/mongodb/mongo-go-driver" "$dir" pushd "$dir" @@ -41,8 +45,18 @@ if [[ "$latestTag" == "$existingTag" ]]; then exit 0 fi +echo "" +echo "> Copy repository" +echo "" + rm -rf mongo cp -r "$dir" "mongo" +rm -rf "$dir" + +echo "" +echo "> Clean repository" +echo "" + rm -rf "mongo/.git" rm -rf "mongo/.evergreen" rm -rf "mongo/cmd" @@ -55,6 +69,10 @@ rm -rf "mongo/vendor" rm -rf "mongo/go.mod" rm -rf "mongo/go.sum" +echo "" +echo "> Update mongoPatchVersion.go" +echo "" + { printf "package goext\n" @@ -66,7 +84,11 @@ rm -rf "mongo/go.sum" } > mongoPatchVersion.go -rm -rf "$dir" +echo "" +echo "> Patch mongo" +echo "" + +git apply -v _data/mongo.patch echo "" echo "Done." \ No newline at end of file diff --git a/mongo/bson/bsoncodec/struct_codec.go b/mongo/bson/bsoncodec/struct_codec.go index da1ae18..d3f8095 100644 --- a/mongo/bson/bsoncodec/struct_codec.go +++ b/mongo/bson/bsoncodec/struct_codec.go @@ -122,6 +122,10 @@ func (sc *StructCodec) EncodeValue(r EncodeContext, vw bsonrw.ValueWriter, val r } var rv reflect.Value for _, desc := range sd.fl { + if desc.omitAlways { + continue + } + if desc.inline == nil { rv = val.Field(desc.idx) } else { @@ -400,15 +404,16 @@ type structDescription struct { } type fieldDescription struct { - name string // BSON key name - fieldName string // struct field name - idx int - omitEmpty bool - minSize bool - truncate bool - inline []int - encoder ValueEncoder - decoder ValueDecoder + name string // BSON key name + fieldName string // struct field name + idx int + omitEmpty bool + omitAlways bool + minSize bool + truncate bool + inline []int + encoder ValueEncoder + decoder ValueDecoder } type byIndex []fieldDescription @@ -491,6 +496,7 @@ func (sc *StructCodec) describeStruct(r *Registry, t reflect.Type) (*structDescr } description.name = stags.Name description.omitEmpty = stags.OmitEmpty + description.omitAlways = stags.OmitAlways description.minSize = stags.MinSize description.truncate = stags.Truncate diff --git a/mongo/bson/bsoncodec/struct_tag_parser.go b/mongo/bson/bsoncodec/struct_tag_parser.go index 62708c5..f9eb604 100644 --- a/mongo/bson/bsoncodec/struct_tag_parser.go +++ b/mongo/bson/bsoncodec/struct_tag_parser.go @@ -52,12 +52,13 @@ func (stpf StructTagParserFunc) ParseStructTags(sf reflect.StructField) (StructT // // TODO(skriptble): Add tags for undefined as nil and for null as nil. type StructTags struct { - Name string - OmitEmpty bool - MinSize bool - Truncate bool - Inline bool - Skip bool + Name string + OmitEmpty bool + OmitAlways bool + MinSize bool + Truncate bool + Inline bool + Skip bool } // DefaultStructTagParser is the StructTagParser used by the StructCodec by default. @@ -108,6 +109,8 @@ func parseTags(key string, tag string) (StructTags, error) { switch str { case "omitempty": st.OmitEmpty = true + case "omitalways": + st.OmitAlways = true case "minsize": st.MinSize = true case "truncate":