Patch mongo (add omitalways
)
This commit is contained in:
parent
d471d7c396
commit
2ec88e81f3
80
_data/mongo.patch
Normal file
80
_data/mongo.patch
Normal file
@ -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":
|
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
dir="/tmp/mongo_repo_$( uuidgen )"
|
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"
|
git clone "https://github.com/mongodb/mongo-go-driver" "$dir"
|
||||||
|
|
||||||
pushd "$dir"
|
pushd "$dir"
|
||||||
@ -41,8 +45,18 @@ if [[ "$latestTag" == "$existingTag" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "> Copy repository"
|
||||||
|
echo ""
|
||||||
|
|
||||||
rm -rf mongo
|
rm -rf mongo
|
||||||
cp -r "$dir" "mongo"
|
cp -r "$dir" "mongo"
|
||||||
|
rm -rf "$dir"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "> Clean repository"
|
||||||
|
echo ""
|
||||||
|
|
||||||
rm -rf "mongo/.git"
|
rm -rf "mongo/.git"
|
||||||
rm -rf "mongo/.evergreen"
|
rm -rf "mongo/.evergreen"
|
||||||
rm -rf "mongo/cmd"
|
rm -rf "mongo/cmd"
|
||||||
@ -55,6 +69,10 @@ rm -rf "mongo/vendor"
|
|||||||
rm -rf "mongo/go.mod"
|
rm -rf "mongo/go.mod"
|
||||||
rm -rf "mongo/go.sum"
|
rm -rf "mongo/go.sum"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "> Update mongoPatchVersion.go"
|
||||||
|
echo ""
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
printf "package goext\n"
|
printf "package goext\n"
|
||||||
@ -66,7 +84,11 @@ rm -rf "mongo/go.sum"
|
|||||||
|
|
||||||
} > mongoPatchVersion.go
|
} > mongoPatchVersion.go
|
||||||
|
|
||||||
rm -rf "$dir"
|
echo ""
|
||||||
|
echo "> Patch mongo"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
git apply -v _data/mongo.patch
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done."
|
echo "Done."
|
@ -122,6 +122,10 @@ func (sc *StructCodec) EncodeValue(r EncodeContext, vw bsonrw.ValueWriter, val r
|
|||||||
}
|
}
|
||||||
var rv reflect.Value
|
var rv reflect.Value
|
||||||
for _, desc := range sd.fl {
|
for _, desc := range sd.fl {
|
||||||
|
if desc.omitAlways {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if desc.inline == nil {
|
if desc.inline == nil {
|
||||||
rv = val.Field(desc.idx)
|
rv = val.Field(desc.idx)
|
||||||
} else {
|
} else {
|
||||||
@ -404,6 +408,7 @@ type fieldDescription struct {
|
|||||||
fieldName string // struct field name
|
fieldName string // struct field name
|
||||||
idx int
|
idx int
|
||||||
omitEmpty bool
|
omitEmpty bool
|
||||||
|
omitAlways bool
|
||||||
minSize bool
|
minSize bool
|
||||||
truncate bool
|
truncate bool
|
||||||
inline []int
|
inline []int
|
||||||
@ -491,6 +496,7 @@ func (sc *StructCodec) describeStruct(r *Registry, t reflect.Type) (*structDescr
|
|||||||
}
|
}
|
||||||
description.name = stags.Name
|
description.name = stags.Name
|
||||||
description.omitEmpty = stags.OmitEmpty
|
description.omitEmpty = stags.OmitEmpty
|
||||||
|
description.omitAlways = stags.OmitAlways
|
||||||
description.minSize = stags.MinSize
|
description.minSize = stags.MinSize
|
||||||
description.truncate = stags.Truncate
|
description.truncate = stags.Truncate
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ func (stpf StructTagParserFunc) ParseStructTags(sf reflect.StructField) (StructT
|
|||||||
type StructTags struct {
|
type StructTags struct {
|
||||||
Name string
|
Name string
|
||||||
OmitEmpty bool
|
OmitEmpty bool
|
||||||
|
OmitAlways bool
|
||||||
MinSize bool
|
MinSize bool
|
||||||
Truncate bool
|
Truncate bool
|
||||||
Inline bool
|
Inline bool
|
||||||
@ -108,6 +109,8 @@ func parseTags(key string, tag string) (StructTags, error) {
|
|||||||
switch str {
|
switch str {
|
||||||
case "omitempty":
|
case "omitempty":
|
||||||
st.OmitEmpty = true
|
st.OmitEmpty = true
|
||||||
|
case "omitalways":
|
||||||
|
st.OmitAlways = true
|
||||||
case "minsize":
|
case "minsize":
|
||||||
st.MinSize = true
|
st.MinSize = true
|
||||||
case "truncate":
|
case "truncate":
|
||||||
|
Loading…
Reference in New Issue
Block a user