Vendor Update (#14496)
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
This commit is contained in:
parent
e45bf12a34
commit
d1353e1f7c
403 changed files with 29737 additions and 14357 deletions
135
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/map_codec.go
generated
vendored
135
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/map_codec.go
generated
vendored
|
@ -20,12 +20,29 @@ var defaultMapCodec = NewMapCodec()
|
|||
|
||||
// MapCodec is the Codec used for map values.
|
||||
type MapCodec struct {
|
||||
DecodeZerosMap bool
|
||||
EncodeNilAsEmpty bool
|
||||
DecodeZerosMap bool
|
||||
EncodeNilAsEmpty bool
|
||||
EncodeKeysWithStringer bool
|
||||
}
|
||||
|
||||
var _ ValueCodec = &MapCodec{}
|
||||
|
||||
// KeyMarshaler is the interface implemented by an object that can marshal itself into a string key.
|
||||
// This applies to types used as map keys and is similar to encoding.TextMarshaler.
|
||||
type KeyMarshaler interface {
|
||||
MarshalKey() (key string, err error)
|
||||
}
|
||||
|
||||
// KeyUnmarshaler is the interface implemented by an object that can unmarshal a string representation
|
||||
// of itself. This applies to types used as map keys and is similar to encoding.TextUnmarshaler.
|
||||
//
|
||||
// UnmarshalKey must be able to decode the form generated by MarshalKey.
|
||||
// UnmarshalKey must copy the text if it wishes to retain the text
|
||||
// after returning.
|
||||
type KeyUnmarshaler interface {
|
||||
UnmarshalKey(key string) error
|
||||
}
|
||||
|
||||
// NewMapCodec returns a MapCodec with options opts.
|
||||
func NewMapCodec(opts ...*bsonoptions.MapCodecOptions) *MapCodec {
|
||||
mapOpt := bsonoptions.MergeMapCodecOptions(opts...)
|
||||
|
@ -37,6 +54,9 @@ func NewMapCodec(opts ...*bsonoptions.MapCodecOptions) *MapCodec {
|
|||
if mapOpt.EncodeNilAsEmpty != nil {
|
||||
codec.EncodeNilAsEmpty = *mapOpt.EncodeNilAsEmpty
|
||||
}
|
||||
if mapOpt.EncodeKeysWithStringer != nil {
|
||||
codec.EncodeKeysWithStringer = *mapOpt.EncodeKeysWithStringer
|
||||
}
|
||||
return &codec
|
||||
}
|
||||
|
||||
|
@ -79,7 +99,11 @@ func (mc *MapCodec) mapEncodeValue(ec EncodeContext, dw bsonrw.DocumentWriter, v
|
|||
|
||||
keys := val.MapKeys()
|
||||
for _, key := range keys {
|
||||
keyStr := fmt.Sprint(key)
|
||||
keyStr, err := mc.encodeKey(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if collisionFn != nil && collisionFn(keyStr) {
|
||||
return fmt.Errorf("Key %s of inlined map conflicts with a struct field name", key)
|
||||
}
|
||||
|
@ -129,6 +153,9 @@ func (mc *MapCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val ref
|
|||
case bsontype.Null:
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return vr.ReadNull()
|
||||
case bsontype.Undefined:
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return vr.ReadUndefined()
|
||||
default:
|
||||
return fmt.Errorf("cannot decode %v into a %s", vrType, val.Type())
|
||||
}
|
||||
|
@ -157,7 +184,6 @@ func (mc *MapCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val ref
|
|||
}
|
||||
|
||||
keyType := val.Type().Key()
|
||||
keyKind := keyType.Kind()
|
||||
|
||||
for {
|
||||
key, vr, err := dr.ReadElement()
|
||||
|
@ -168,29 +194,15 @@ func (mc *MapCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val ref
|
|||
return err
|
||||
}
|
||||
|
||||
k := reflect.ValueOf(key)
|
||||
if keyType != tString {
|
||||
switch keyKind {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Float32, reflect.Float64:
|
||||
parsed, err := strconv.ParseFloat(k.String(), 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Map key is defined to be a decimal type (%v) but got error %v", keyKind, err)
|
||||
}
|
||||
k = reflect.ValueOf(parsed)
|
||||
case reflect.String: // if keyType wraps string
|
||||
default:
|
||||
return fmt.Errorf("BSON map must have string or decimal keys. Got:%v", val.Type())
|
||||
}
|
||||
|
||||
k = k.Convert(keyType)
|
||||
k, err := mc.decodeKey(key, keyType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
elem := reflect.New(eType).Elem()
|
||||
err = decoder.DecodeValue(dc, vr, elem)
|
||||
if err != nil {
|
||||
return err
|
||||
return newDecodeError(key, err)
|
||||
}
|
||||
|
||||
val.SetMapIndex(k, elem)
|
||||
|
@ -204,3 +216,82 @@ func clearMap(m reflect.Value) {
|
|||
m.SetMapIndex(k, none)
|
||||
}
|
||||
}
|
||||
|
||||
func (mc *MapCodec) encodeKey(val reflect.Value) (string, error) {
|
||||
if mc.EncodeKeysWithStringer {
|
||||
return fmt.Sprint(val), nil
|
||||
}
|
||||
|
||||
// keys of any string type are used directly
|
||||
if val.Kind() == reflect.String {
|
||||
return val.String(), nil
|
||||
}
|
||||
// KeyMarshalers are marshaled
|
||||
if km, ok := val.Interface().(KeyMarshaler); ok {
|
||||
if val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
return "", nil
|
||||
}
|
||||
buf, err := km.MarshalKey()
|
||||
if err == nil {
|
||||
return buf, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch val.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return strconv.FormatInt(val.Int(), 10), nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return strconv.FormatUint(val.Uint(), 10), nil
|
||||
}
|
||||
return "", fmt.Errorf("unsupported key type: %v", val.Type())
|
||||
}
|
||||
|
||||
var keyUnmarshalerType = reflect.TypeOf((*KeyUnmarshaler)(nil)).Elem()
|
||||
|
||||
func (mc *MapCodec) decodeKey(key string, keyType reflect.Type) (reflect.Value, error) {
|
||||
keyVal := reflect.ValueOf(key)
|
||||
var err error
|
||||
switch {
|
||||
// First, if EncodeKeysWithStringer is not enabled, try to decode withKeyUnmarshaler
|
||||
case !mc.EncodeKeysWithStringer && reflect.PtrTo(keyType).Implements(keyUnmarshalerType):
|
||||
keyVal = reflect.New(keyType)
|
||||
v := keyVal.Interface().(KeyUnmarshaler)
|
||||
err = v.UnmarshalKey(key)
|
||||
keyVal = keyVal.Elem()
|
||||
// Otherwise, go to type specific behavior
|
||||
default:
|
||||
switch keyType.Kind() {
|
||||
case reflect.String:
|
||||
keyVal = reflect.ValueOf(key).Convert(keyType)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
s := string(key)
|
||||
n, parseErr := strconv.ParseInt(s, 10, 64)
|
||||
if parseErr != nil || reflect.Zero(keyType).OverflowInt(n) {
|
||||
err = fmt.Errorf("failed to unmarshal number key %v", s)
|
||||
}
|
||||
keyVal = reflect.ValueOf(n).Convert(keyType)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
s := string(key)
|
||||
n, parseErr := strconv.ParseUint(s, 10, 64)
|
||||
if parseErr != nil || reflect.Zero(keyType).OverflowUint(n) {
|
||||
err = fmt.Errorf("failed to unmarshal number key %v", s)
|
||||
break
|
||||
}
|
||||
keyVal = reflect.ValueOf(n).Convert(keyType)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
if mc.EncodeKeysWithStringer {
|
||||
parsed, err := strconv.ParseFloat(key, 64)
|
||||
if err != nil {
|
||||
return keyVal, fmt.Errorf("Map key is defined to be a decimal type (%v) but got error %v", keyType.Kind(), err)
|
||||
}
|
||||
keyVal = reflect.ValueOf(parsed)
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
return keyVal, fmt.Errorf("unsupported key type: %v", keyType)
|
||||
}
|
||||
}
|
||||
return keyVal, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue