forked from forgejo/forgejo
[Vendor] Update directly used dependencys (#15593)
* update github.com/blevesearch/bleve v2.0.2 -> v2.0.3 * github.com/denisenkom/go-mssqldb v0.9.0 -> v0.10.0 * github.com/editorconfig/editorconfig-core-go v2.4.1 -> v2.4.2 * github.com/go-chi/cors v1.1.1 -> v1.2.0 * github.com/go-git/go-billy v5.0.0 -> v5.1.0 * github.com/go-git/go-git v5.2.0 -> v5.3.0 * github.com/go-ldap/ldap v3.2.4 -> v3.3.0 * github.com/go-redis/redis v8.6.0 -> v8.8.2 * github.com/go-sql-driver/mysql v1.5.0 -> v1.6.0 * github.com/go-swagger/go-swagger v0.26.1 -> v0.27.0 * github.com/lib/pq v1.9.0 -> v1.10.1 * github.com/mattn/go-sqlite3 v1.14.6 -> v1.14.7 * github.com/go-testfixtures/testfixtures v3.5.0 -> v3.6.0 * github.com/issue9/identicon v1.0.1 -> v1.2.0 * github.com/klauspost/compress v1.11.8 -> v1.12.1 * github.com/mgechev/revive v1.0.3 -> v1.0.6 * github.com/microcosm-cc/bluemonday v1.0.7 -> v1.0.8 * github.com/niklasfasching/go-org v1.4.0 -> v1.5.0 * github.com/olivere/elastic v7.0.22 -> v7.0.24 * github.com/pelletier/go-toml v1.8.1 -> v1.9.0 * github.com/prometheus/client_golang v1.9.0 -> v1.10.0 * github.com/xanzy/go-gitlab v0.44.0 -> v0.48.0 * github.com/yuin/goldmark v1.3.3 -> v1.3.5 * github.com/6543/go-version v1.2.4 -> v1.3.1 * do github.com/lib/pq v1.10.0 -> v1.10.1 again ...
This commit is contained in:
parent
834fc74873
commit
792b4dba2c
558 changed files with 32080 additions and 24669 deletions
50
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/array_codec.go
generated
vendored
Normal file
50
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/array_codec.go
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) MongoDB, Inc. 2017-present.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
package bsoncodec
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
|
||||
)
|
||||
|
||||
// ArrayCodec is the Codec used for bsoncore.Array values.
|
||||
type ArrayCodec struct{}
|
||||
|
||||
var defaultArrayCodec = NewArrayCodec()
|
||||
|
||||
// NewArrayCodec returns an ArrayCodec.
|
||||
func NewArrayCodec() *ArrayCodec {
|
||||
return &ArrayCodec{}
|
||||
}
|
||||
|
||||
// EncodeValue is the ValueEncoder for bsoncore.Array values.
|
||||
func (ac *ArrayCodec) EncodeValue(ec EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error {
|
||||
if !val.IsValid() || val.Type() != tCoreArray {
|
||||
return ValueEncoderError{Name: "CoreArrayEncodeValue", Types: []reflect.Type{tCoreArray}, Received: val}
|
||||
}
|
||||
|
||||
arr := val.Interface().(bsoncore.Array)
|
||||
return bsonrw.Copier{}.CopyArrayFromBytes(vw, arr)
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoder for bsoncore.Array values.
|
||||
func (ac *ArrayCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tCoreArray {
|
||||
return ValueDecoderError{Name: "CoreArrayDecodeValue", Types: []reflect.Type{tCoreArray}, Received: val}
|
||||
}
|
||||
|
||||
if val.IsNil() {
|
||||
val.Set(reflect.MakeSlice(val.Type(), 0, 0))
|
||||
}
|
||||
|
||||
val.SetLen(0)
|
||||
arr, err := bsonrw.Copier{}.AppendArrayBytes(val.Interface().(bsoncore.Array), vr)
|
||||
val.Set(reflect.ValueOf(arr))
|
||||
return err
|
||||
}
|
53
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/bsoncodec.go
generated
vendored
53
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/bsoncodec.go
generated
vendored
|
@ -15,6 +15,10 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
)
|
||||
|
||||
var (
|
||||
emptyValue = reflect.Value{}
|
||||
)
|
||||
|
||||
// Marshaler is an interface implemented by types that can marshal themselves
|
||||
// into a BSON document represented as bytes. The bytes returned must be a valid
|
||||
// BSON document if the error is nil.
|
||||
|
@ -156,6 +160,55 @@ func (fn ValueDecoderFunc) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader,
|
|||
return fn(dc, vr, val)
|
||||
}
|
||||
|
||||
// typeDecoder is the interface implemented by types that can handle the decoding of a value given its type.
|
||||
type typeDecoder interface {
|
||||
decodeType(DecodeContext, bsonrw.ValueReader, reflect.Type) (reflect.Value, error)
|
||||
}
|
||||
|
||||
// typeDecoderFunc is an adapter function that allows a function with the correct signature to be used as a typeDecoder.
|
||||
type typeDecoderFunc func(DecodeContext, bsonrw.ValueReader, reflect.Type) (reflect.Value, error)
|
||||
|
||||
func (fn typeDecoderFunc) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
return fn(dc, vr, t)
|
||||
}
|
||||
|
||||
// decodeAdapter allows two functions with the correct signatures to be used as both a ValueDecoder and typeDecoder.
|
||||
type decodeAdapter struct {
|
||||
ValueDecoderFunc
|
||||
typeDecoderFunc
|
||||
}
|
||||
|
||||
var _ ValueDecoder = decodeAdapter{}
|
||||
var _ typeDecoder = decodeAdapter{}
|
||||
|
||||
// decodeTypeOrValue calls decoder.decodeType is decoder is a typeDecoder. Otherwise, it allocates a new element of type
|
||||
// t and calls decoder.DecodeValue on it.
|
||||
func decodeTypeOrValue(decoder ValueDecoder, dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
td, _ := decoder.(typeDecoder)
|
||||
return decodeTypeOrValueWithInfo(decoder, td, dc, vr, t, true)
|
||||
}
|
||||
|
||||
func decodeTypeOrValueWithInfo(vd ValueDecoder, td typeDecoder, dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type, convert bool) (reflect.Value, error) {
|
||||
if td != nil {
|
||||
val, err := td.decodeType(dc, vr, t)
|
||||
if err == nil && convert && val.Type() != t {
|
||||
// This conversion step is necessary for slices and maps. If a user declares variables like:
|
||||
//
|
||||
// type myBool bool
|
||||
// var m map[string]myBool
|
||||
//
|
||||
// and tries to decode BSON bytes into the map, the decoding will fail if this conversion is not present
|
||||
// because we'll try to assign a value of type bool to one of type myBool.
|
||||
val = val.Convert(t)
|
||||
}
|
||||
return val, err
|
||||
}
|
||||
|
||||
val := reflect.New(t).Elem()
|
||||
err := vd.DecodeValue(dc, vr, val)
|
||||
return val, err
|
||||
}
|
||||
|
||||
// CodecZeroer is the interface implemented by Codecs that can also determine if
|
||||
// a value of the type that would be encoded is zero.
|
||||
type CodecZeroer interface {
|
||||
|
|
55
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/byte_slice_codec.go
generated
vendored
55
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/byte_slice_codec.go
generated
vendored
|
@ -15,14 +15,17 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
)
|
||||
|
||||
var defaultByteSliceCodec = NewByteSliceCodec()
|
||||
|
||||
// ByteSliceCodec is the Codec used for []byte values.
|
||||
type ByteSliceCodec struct {
|
||||
EncodeNilAsEmpty bool
|
||||
}
|
||||
|
||||
var _ ValueCodec = &ByteSliceCodec{}
|
||||
var (
|
||||
defaultByteSliceCodec = NewByteSliceCodec()
|
||||
|
||||
_ ValueCodec = defaultByteSliceCodec
|
||||
_ typeDecoder = defaultByteSliceCodec
|
||||
)
|
||||
|
||||
// NewByteSliceCodec returns a StringCodec with options opts.
|
||||
func NewByteSliceCodec(opts ...*bsonoptions.ByteSliceCodecOptions) *ByteSliceCodec {
|
||||
|
@ -45,10 +48,13 @@ func (bsc *ByteSliceCodec) EncodeValue(ec EncodeContext, vw bsonrw.ValueWriter,
|
|||
return vw.WriteBinary(val.Interface().([]byte))
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoder for []byte.
|
||||
func (bsc *ByteSliceCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tByteSlice {
|
||||
return ValueDecoderError{Name: "ByteSliceDecodeValue", Types: []reflect.Type{tByteSlice}, Received: val}
|
||||
func (bsc *ByteSliceCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
if t != tByteSlice {
|
||||
return emptyValue, ValueDecoderError{
|
||||
Name: "ByteSliceDecodeValue",
|
||||
Types: []reflect.Type{tByteSlice},
|
||||
Received: reflect.Zero(t),
|
||||
}
|
||||
}
|
||||
|
||||
var data []byte
|
||||
|
@ -57,34 +63,49 @@ func (bsc *ByteSliceCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader,
|
|||
case bsontype.String:
|
||||
str, err := vr.ReadString()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
data = []byte(str)
|
||||
case bsontype.Symbol:
|
||||
sym, err := vr.ReadSymbol()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
data = []byte(sym)
|
||||
case bsontype.Binary:
|
||||
var subtype byte
|
||||
data, subtype, err = vr.ReadBinary()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
if subtype != bsontype.BinaryGeneric && subtype != bsontype.BinaryBinaryOld {
|
||||
return fmt.Errorf("ByteSliceDecodeValue can only be used to decode subtype 0x00 or 0x02 for %s, got %v", bsontype.Binary, subtype)
|
||||
return emptyValue, decodeBinaryError{subtype: subtype, typeName: "[]byte"}
|
||||
}
|
||||
case bsontype.Null:
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return vr.ReadNull()
|
||||
err = vr.ReadNull()
|
||||
case bsontype.Undefined:
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return vr.ReadUndefined()
|
||||
err = vr.ReadUndefined()
|
||||
default:
|
||||
return fmt.Errorf("cannot decode %v into a []byte", vrType)
|
||||
return emptyValue, fmt.Errorf("cannot decode %v into a []byte", vrType)
|
||||
}
|
||||
if err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
|
||||
val.Set(reflect.ValueOf(data))
|
||||
return reflect.ValueOf(data), nil
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoder for []byte.
|
||||
func (bsc *ByteSliceCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tByteSlice {
|
||||
return ValueDecoderError{Name: "ByteSliceDecodeValue", Types: []reflect.Type{tByteSlice}, Received: val}
|
||||
}
|
||||
|
||||
elem, err := bsc.decodeType(dc, vr, tByteSlice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val.Set(elem)
|
||||
return nil
|
||||
}
|
||||
|
|
1093
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/default_value_decoders.go
generated
vendored
1093
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/default_value_decoders.go
generated
vendored
File diff suppressed because it is too large
Load diff
1
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/default_value_encoders.go
generated
vendored
1
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/default_value_encoders.go
generated
vendored
|
@ -70,6 +70,7 @@ func (dve DefaultValueEncoders) RegisterDefaultEncoders(rb *RegistryBuilder) {
|
|||
RegisterTypeEncoder(tByteSlice, defaultByteSliceCodec).
|
||||
RegisterTypeEncoder(tTime, defaultTimeCodec).
|
||||
RegisterTypeEncoder(tEmpty, defaultEmptyInterfaceCodec).
|
||||
RegisterTypeEncoder(tCoreArray, defaultArrayCodec).
|
||||
RegisterTypeEncoder(tOID, ValueEncoderFunc(dve.ObjectIDEncodeValue)).
|
||||
RegisterTypeEncoder(tDecimal, ValueEncoderFunc(dve.Decimal128EncodeValue)).
|
||||
RegisterTypeEncoder(tJSONNumber, ValueEncoderFunc(dve.JSONNumberEncodeValue)).
|
||||
|
|
43
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/empty_interface_codec.go
generated
vendored
43
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/empty_interface_codec.go
generated
vendored
|
@ -15,14 +15,17 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var defaultEmptyInterfaceCodec = NewEmptyInterfaceCodec()
|
||||
|
||||
// EmptyInterfaceCodec is the Codec used for interface{} values.
|
||||
type EmptyInterfaceCodec struct {
|
||||
DecodeBinaryAsSlice bool
|
||||
}
|
||||
|
||||
var _ ValueCodec = &EmptyInterfaceCodec{}
|
||||
var (
|
||||
defaultEmptyInterfaceCodec = NewEmptyInterfaceCodec()
|
||||
|
||||
_ ValueCodec = defaultEmptyInterfaceCodec
|
||||
_ typeDecoder = defaultEmptyInterfaceCodec
|
||||
)
|
||||
|
||||
// NewEmptyInterfaceCodec returns a EmptyInterfaceCodec with options opts.
|
||||
func NewEmptyInterfaceCodec(opts ...*bsonoptions.EmptyInterfaceCodecOptions) *EmptyInterfaceCodec {
|
||||
|
@ -86,33 +89,31 @@ func (eic EmptyInterfaceCodec) getEmptyInterfaceDecodeType(dc DecodeContext, val
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoderFunc for interface{}.
|
||||
func (eic EmptyInterfaceCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tEmpty {
|
||||
return ValueDecoderError{Name: "EmptyInterfaceDecodeValue", Types: []reflect.Type{tEmpty}, Received: val}
|
||||
func (eic EmptyInterfaceCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
if t != tEmpty {
|
||||
return emptyValue, ValueDecoderError{Name: "EmptyInterfaceDecodeValue", Types: []reflect.Type{tEmpty}, Received: reflect.Zero(t)}
|
||||
}
|
||||
|
||||
rtype, err := eic.getEmptyInterfaceDecodeType(dc, vr.Type())
|
||||
if err != nil {
|
||||
switch vr.Type() {
|
||||
case bsontype.Null:
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return vr.ReadNull()
|
||||
return reflect.Zero(t), vr.ReadNull()
|
||||
default:
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
}
|
||||
|
||||
decoder, err := dc.LookupDecoder(rtype)
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
|
||||
elem := reflect.New(rtype).Elem()
|
||||
err = decoder.DecodeValue(dc, vr, elem)
|
||||
elem, err := decodeTypeOrValue(decoder, dc, vr, rtype)
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
|
||||
if eic.DecodeBinaryAsSlice && rtype == tBinary {
|
||||
binElem := elem.Interface().(primitive.Binary)
|
||||
if binElem.Subtype == bsontype.BinaryGeneric || binElem.Subtype == bsontype.BinaryBinaryOld {
|
||||
|
@ -120,6 +121,20 @@ func (eic EmptyInterfaceCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueRead
|
|||
}
|
||||
}
|
||||
|
||||
return elem, nil
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoderFunc for interface{}.
|
||||
func (eic EmptyInterfaceCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tEmpty {
|
||||
return ValueDecoderError{Name: "EmptyInterfaceDecodeValue", Types: []reflect.Type{tEmpty}, Received: val}
|
||||
}
|
||||
|
||||
elem, err := eic.decodeType(dc, vr, val.Type())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val.Set(elem)
|
||||
return nil
|
||||
}
|
||||
|
|
4
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/map_codec.go
generated
vendored
4
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/map_codec.go
generated
vendored
|
@ -178,6 +178,7 @@ func (mc *MapCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val ref
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eTypeDecoder, _ := decoder.(typeDecoder)
|
||||
|
||||
if eType == tEmpty {
|
||||
dc.Ancestor = val.Type()
|
||||
|
@ -199,8 +200,7 @@ func (mc *MapCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val ref
|
|||
return err
|
||||
}
|
||||
|
||||
elem := reflect.New(eType).Elem()
|
||||
err = decoder.DecodeValue(dc, vr, elem)
|
||||
elem, err := decodeTypeOrValueWithInfo(decoder, eTypeDecoder, dc, vr, eType, true)
|
||||
if err != nil {
|
||||
return newDecodeError(key, err)
|
||||
}
|
||||
|
|
53
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/string_codec.go
generated
vendored
53
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/string_codec.go
generated
vendored
|
@ -15,14 +15,17 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
)
|
||||
|
||||
var defaultStringCodec = NewStringCodec()
|
||||
|
||||
// StringCodec is the Codec used for struct values.
|
||||
type StringCodec struct {
|
||||
DecodeObjectIDAsHex bool
|
||||
}
|
||||
|
||||
var _ ValueCodec = &StringCodec{}
|
||||
var (
|
||||
defaultStringCodec = NewStringCodec()
|
||||
|
||||
_ ValueCodec = defaultStringCodec
|
||||
_ typeDecoder = defaultStringCodec
|
||||
)
|
||||
|
||||
// NewStringCodec returns a StringCodec with options opts.
|
||||
func NewStringCodec(opts ...*bsonoptions.StringCodecOptions) *StringCodec {
|
||||
|
@ -43,23 +46,27 @@ func (sc *StringCodec) EncodeValue(ectx EncodeContext, vw bsonrw.ValueWriter, va
|
|||
return vw.WriteString(val.String())
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoder for string types.
|
||||
func (sc *StringCodec) DecodeValue(dctx DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Kind() != reflect.String {
|
||||
return ValueDecoderError{Name: "StringDecodeValue", Kinds: []reflect.Kind{reflect.String}, Received: val}
|
||||
func (sc *StringCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
if t.Kind() != reflect.String {
|
||||
return emptyValue, ValueDecoderError{
|
||||
Name: "StringDecodeValue",
|
||||
Kinds: []reflect.Kind{reflect.String},
|
||||
Received: reflect.Zero(t),
|
||||
}
|
||||
}
|
||||
|
||||
var str string
|
||||
var err error
|
||||
switch vr.Type() {
|
||||
case bsontype.String:
|
||||
str, err = vr.ReadString()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.ObjectID:
|
||||
oid, err := vr.ReadObjectID()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
if sc.DecodeObjectIDAsHex {
|
||||
str = oid.Hex()
|
||||
|
@ -70,29 +77,43 @@ func (sc *StringCodec) DecodeValue(dctx DecodeContext, vr bsonrw.ValueReader, va
|
|||
case bsontype.Symbol:
|
||||
str, err = vr.ReadSymbol()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.Binary:
|
||||
data, subtype, err := vr.ReadBinary()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
if subtype != bsontype.BinaryGeneric && subtype != bsontype.BinaryBinaryOld {
|
||||
return fmt.Errorf("SliceDecodeValue can only be used to decode subtype 0x00 or 0x02 for %s, got %v", bsontype.Binary, subtype)
|
||||
return emptyValue, decodeBinaryError{subtype: subtype, typeName: "string"}
|
||||
}
|
||||
str = string(data)
|
||||
case bsontype.Null:
|
||||
if err = vr.ReadNull(); err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.Undefined:
|
||||
if err = vr.ReadUndefined(); err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("cannot decode %v into a string type", vr.Type())
|
||||
return emptyValue, fmt.Errorf("cannot decode %v into a string type", vr.Type())
|
||||
}
|
||||
|
||||
val.SetString(str)
|
||||
return reflect.ValueOf(str), nil
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoder for string types.
|
||||
func (sc *StringCodec) DecodeValue(dctx DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Kind() != reflect.String {
|
||||
return ValueDecoderError{Name: "StringDecodeValue", Kinds: []reflect.Kind{reflect.String}, Received: val}
|
||||
}
|
||||
|
||||
elem, err := sc.decodeType(dctx, vr, val.Type())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val.SetString(elem.String())
|
||||
return nil
|
||||
}
|
||||
|
|
20
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/struct_tag_parser.go
generated
vendored
20
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/struct_tag_parser.go
generated
vendored
|
@ -91,6 +91,10 @@ var DefaultStructTagParser StructTagParserFunc = func(sf reflect.StructField) (S
|
|||
if !ok && !strings.Contains(string(sf.Tag), ":") && len(sf.Tag) > 0 {
|
||||
tag = string(sf.Tag)
|
||||
}
|
||||
return parseTags(key, tag)
|
||||
}
|
||||
|
||||
func parseTags(key string, tag string) (StructTags, error) {
|
||||
var st StructTags
|
||||
if tag == "-" {
|
||||
st.Skip = true
|
||||
|
@ -117,3 +121,19 @@ var DefaultStructTagParser StructTagParserFunc = func(sf reflect.StructField) (S
|
|||
|
||||
return st, nil
|
||||
}
|
||||
|
||||
// JSONFallbackStructTagParser has the same behavior as DefaultStructTagParser
|
||||
// but will also fallback to parsing the json tag instead on a field where the
|
||||
// bson tag isn't available.
|
||||
var JSONFallbackStructTagParser StructTagParserFunc = func(sf reflect.StructField) (StructTags, error) {
|
||||
key := strings.ToLower(sf.Name)
|
||||
tag, ok := sf.Tag.Lookup("bson")
|
||||
if !ok {
|
||||
tag, ok = sf.Tag.Lookup("json")
|
||||
}
|
||||
if !ok && !strings.Contains(string(sf.Tag), ":") && len(sf.Tag) > 0 {
|
||||
tag = string(sf.Tag)
|
||||
}
|
||||
|
||||
return parseTags(key, tag)
|
||||
}
|
||||
|
|
52
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/time_codec.go
generated
vendored
52
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/time_codec.go
generated
vendored
|
@ -21,14 +21,17 @@ const (
|
|||
timeFormatString = "2006-01-02T15:04:05.999Z07:00"
|
||||
)
|
||||
|
||||
var defaultTimeCodec = NewTimeCodec()
|
||||
|
||||
// TimeCodec is the Codec used for time.Time values.
|
||||
type TimeCodec struct {
|
||||
UseLocalTimeZone bool
|
||||
}
|
||||
|
||||
var _ ValueCodec = &TimeCodec{}
|
||||
var (
|
||||
defaultTimeCodec = NewTimeCodec()
|
||||
|
||||
_ ValueCodec = defaultTimeCodec
|
||||
_ typeDecoder = defaultTimeCodec
|
||||
)
|
||||
|
||||
// NewTimeCodec returns a TimeCodec with options opts.
|
||||
func NewTimeCodec(opts ...*bsonoptions.TimeCodecOptions) *TimeCodec {
|
||||
|
@ -41,10 +44,13 @@ func NewTimeCodec(opts ...*bsonoptions.TimeCodecOptions) *TimeCodec {
|
|||
return &codec
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoderFunc for time.Time.
|
||||
func (tc *TimeCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tTime {
|
||||
return ValueDecoderError{Name: "TimeDecodeValue", Types: []reflect.Type{tTime}, Received: val}
|
||||
func (tc *TimeCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
if t != tTime {
|
||||
return emptyValue, ValueDecoderError{
|
||||
Name: "TimeDecodeValue",
|
||||
Types: []reflect.Type{tTime},
|
||||
Received: reflect.Zero(t),
|
||||
}
|
||||
}
|
||||
|
||||
var timeVal time.Time
|
||||
|
@ -52,47 +58,61 @@ func (tc *TimeCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val re
|
|||
case bsontype.DateTime:
|
||||
dt, err := vr.ReadDateTime()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
timeVal = time.Unix(dt/1000, dt%1000*1000000)
|
||||
case bsontype.String:
|
||||
// assume strings are in the isoTimeFormat
|
||||
timeStr, err := vr.ReadString()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
timeVal, err = time.Parse(timeFormatString, timeStr)
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.Int64:
|
||||
i64, err := vr.ReadInt64()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
timeVal = time.Unix(i64/1000, i64%1000*1000000)
|
||||
case bsontype.Timestamp:
|
||||
t, _, err := vr.ReadTimestamp()
|
||||
if err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
timeVal = time.Unix(int64(t), 0)
|
||||
case bsontype.Null:
|
||||
if err := vr.ReadNull(); err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.Undefined:
|
||||
if err := vr.ReadUndefined(); err != nil {
|
||||
return err
|
||||
return emptyValue, err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("cannot decode %v into a time.Time", vrType)
|
||||
return emptyValue, fmt.Errorf("cannot decode %v into a time.Time", vrType)
|
||||
}
|
||||
|
||||
if !tc.UseLocalTimeZone {
|
||||
timeVal = timeVal.UTC()
|
||||
}
|
||||
val.Set(reflect.ValueOf(timeVal))
|
||||
return reflect.ValueOf(timeVal), nil
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoderFunc for time.Time.
|
||||
func (tc *TimeCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() || val.Type() != tTime {
|
||||
return ValueDecoderError{Name: "TimeDecodeValue", Types: []reflect.Type{tTime}, Received: val}
|
||||
}
|
||||
|
||||
elem, err := tc.decodeType(dc, vr, tTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val.Set(elem)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
1
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/types.go
generated
vendored
1
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/types.go
generated
vendored
|
@ -79,3 +79,4 @@ var tA = reflect.TypeOf(primitive.A{})
|
|||
var tE = reflect.TypeOf(primitive.E{})
|
||||
|
||||
var tCoreDocument = reflect.TypeOf(bsoncore.Document{})
|
||||
var tCoreArray = reflect.TypeOf(bsoncore.Array{})
|
||||
|
|
175
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/uint_codec.go
generated
vendored
175
vendor/go.mongodb.org/mongo-driver/bson/bsoncodec/uint_codec.go
generated
vendored
|
@ -7,7 +7,6 @@
|
|||
package bsoncodec
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
|
@ -17,14 +16,17 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
)
|
||||
|
||||
var defaultUIntCodec = NewUIntCodec()
|
||||
|
||||
// UIntCodec is the Codec used for uint values.
|
||||
type UIntCodec struct {
|
||||
EncodeToMinSize bool
|
||||
}
|
||||
|
||||
var _ ValueCodec = &UIntCodec{}
|
||||
var (
|
||||
defaultUIntCodec = NewUIntCodec()
|
||||
|
||||
_ ValueCodec = defaultUIntCodec
|
||||
_ typeDecoder = defaultUIntCodec
|
||||
)
|
||||
|
||||
// NewUIntCodec returns a UIntCodec with options opts.
|
||||
func NewUIntCodec(opts ...*bsonoptions.UIntCodecOptions) *UIntCodec {
|
||||
|
@ -64,6 +66,93 @@ func (uic *UIntCodec) EncodeValue(ec EncodeContext, vw bsonrw.ValueWriter, val r
|
|||
}
|
||||
}
|
||||
|
||||
func (uic *UIntCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t reflect.Type) (reflect.Value, error) {
|
||||
var i64 int64
|
||||
var err error
|
||||
switch vrType := vr.Type(); vrType {
|
||||
case bsontype.Int32:
|
||||
i32, err := vr.ReadInt32()
|
||||
if err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
i64 = int64(i32)
|
||||
case bsontype.Int64:
|
||||
i64, err = vr.ReadInt64()
|
||||
if err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.Double:
|
||||
f64, err := vr.ReadDouble()
|
||||
if err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
if !dc.Truncate && math.Floor(f64) != f64 {
|
||||
return emptyValue, errCannotTruncate
|
||||
}
|
||||
if f64 > float64(math.MaxInt64) {
|
||||
return emptyValue, fmt.Errorf("%g overflows int64", f64)
|
||||
}
|
||||
i64 = int64(f64)
|
||||
case bsontype.Boolean:
|
||||
b, err := vr.ReadBoolean()
|
||||
if err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
if b {
|
||||
i64 = 1
|
||||
}
|
||||
case bsontype.Null:
|
||||
if err = vr.ReadNull(); err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
case bsontype.Undefined:
|
||||
if err = vr.ReadUndefined(); err != nil {
|
||||
return emptyValue, err
|
||||
}
|
||||
default:
|
||||
return emptyValue, fmt.Errorf("cannot decode %v into an integer type", vrType)
|
||||
}
|
||||
|
||||
switch t.Kind() {
|
||||
case reflect.Uint8:
|
||||
if i64 < 0 || i64 > math.MaxUint8 {
|
||||
return emptyValue, fmt.Errorf("%d overflows uint8", i64)
|
||||
}
|
||||
|
||||
return reflect.ValueOf(uint8(i64)), nil
|
||||
case reflect.Uint16:
|
||||
if i64 < 0 || i64 > math.MaxUint16 {
|
||||
return emptyValue, fmt.Errorf("%d overflows uint16", i64)
|
||||
}
|
||||
|
||||
return reflect.ValueOf(uint16(i64)), nil
|
||||
case reflect.Uint32:
|
||||
if i64 < 0 || i64 > math.MaxUint32 {
|
||||
return emptyValue, fmt.Errorf("%d overflows uint32", i64)
|
||||
}
|
||||
|
||||
return reflect.ValueOf(uint32(i64)), nil
|
||||
case reflect.Uint64:
|
||||
if i64 < 0 {
|
||||
return emptyValue, fmt.Errorf("%d overflows uint64", i64)
|
||||
}
|
||||
|
||||
return reflect.ValueOf(uint64(i64)), nil
|
||||
case reflect.Uint:
|
||||
if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint
|
||||
return emptyValue, fmt.Errorf("%d overflows uint", i64)
|
||||
}
|
||||
|
||||
return reflect.ValueOf(uint(i64)), nil
|
||||
default:
|
||||
return emptyValue, ValueDecoderError{
|
||||
Name: "UintDecodeValue",
|
||||
Kinds: []reflect.Kind{reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint},
|
||||
Received: reflect.Zero(t),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeValue is the ValueDecoder for uint types.
|
||||
func (uic *UIntCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if !val.CanSet() {
|
||||
|
@ -74,81 +163,11 @@ func (uic *UIntCodec) DecodeValue(dc DecodeContext, vr bsonrw.ValueReader, val r
|
|||
}
|
||||
}
|
||||
|
||||
var i64 int64
|
||||
var err error
|
||||
switch vrType := vr.Type(); vrType {
|
||||
case bsontype.Int32:
|
||||
i32, err := vr.ReadInt32()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i64 = int64(i32)
|
||||
case bsontype.Int64:
|
||||
i64, err = vr.ReadInt64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case bsontype.Double:
|
||||
f64, err := vr.ReadDouble()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !dc.Truncate && math.Floor(f64) != f64 {
|
||||
return errors.New("UintDecodeValue can only truncate float64 to an integer type when truncation is enabled")
|
||||
}
|
||||
if f64 > float64(math.MaxInt64) {
|
||||
return fmt.Errorf("%g overflows int64", f64)
|
||||
}
|
||||
i64 = int64(f64)
|
||||
case bsontype.Boolean:
|
||||
b, err := vr.ReadBoolean()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b {
|
||||
i64 = 1
|
||||
}
|
||||
case bsontype.Null:
|
||||
if err = vr.ReadNull(); err != nil {
|
||||
return err
|
||||
}
|
||||
case bsontype.Undefined:
|
||||
if err = vr.ReadUndefined(); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("cannot decode %v into an integer type", vrType)
|
||||
elem, err := uic.decodeType(dc, vr, val.Type())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch val.Kind() {
|
||||
case reflect.Uint8:
|
||||
if i64 < 0 || i64 > math.MaxUint8 {
|
||||
return fmt.Errorf("%d overflows uint8", i64)
|
||||
}
|
||||
case reflect.Uint16:
|
||||
if i64 < 0 || i64 > math.MaxUint16 {
|
||||
return fmt.Errorf("%d overflows uint16", i64)
|
||||
}
|
||||
case reflect.Uint32:
|
||||
if i64 < 0 || i64 > math.MaxUint32 {
|
||||
return fmt.Errorf("%d overflows uint32", i64)
|
||||
}
|
||||
case reflect.Uint64:
|
||||
if i64 < 0 {
|
||||
return fmt.Errorf("%d overflows uint64", i64)
|
||||
}
|
||||
case reflect.Uint:
|
||||
if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint
|
||||
return fmt.Errorf("%d overflows uint", i64)
|
||||
}
|
||||
default:
|
||||
return ValueDecoderError{
|
||||
Name: "UintDecodeValue",
|
||||
Kinds: []reflect.Kind{reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint},
|
||||
Received: val,
|
||||
}
|
||||
}
|
||||
|
||||
val.SetUint(uint64(i64))
|
||||
val.SetUint(elem.Uint())
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue