mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-28 17:19:24 +00:00
Update direct dependencies where possible
This commit is contained in:
54
vendor/github.com/gorilla/schema/cache.go
generated
vendored
54
vendor/github.com/gorilla/schema/cache.go
generated
vendored
@ -18,13 +18,9 @@ var invalidPath = errors.New("schema: invalid path")
|
||||
func newCache() *cache {
|
||||
c := cache{
|
||||
m: make(map[reflect.Type]*structInfo),
|
||||
conv: make(map[reflect.Kind]Converter),
|
||||
regconv: make(map[reflect.Type]Converter),
|
||||
tag: "schema",
|
||||
}
|
||||
for k, v := range converters {
|
||||
c.conv[k] = v
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
@ -32,11 +28,15 @@ func newCache() *cache {
|
||||
type cache struct {
|
||||
l sync.RWMutex
|
||||
m map[reflect.Type]*structInfo
|
||||
conv map[reflect.Kind]Converter
|
||||
regconv map[reflect.Type]Converter
|
||||
tag string
|
||||
}
|
||||
|
||||
// registerConverter registers a converter function for a custom type.
|
||||
func (c *cache) registerConverter(value interface{}, converterFunc Converter) {
|
||||
c.regconv[reflect.TypeOf(value)] = converterFunc
|
||||
}
|
||||
|
||||
// parsePath parses a path in dotted notation verifying that it is a valid
|
||||
// path to a struct field.
|
||||
//
|
||||
@ -63,7 +63,7 @@ func (c *cache) parsePath(p string, t reflect.Type) ([]pathPart, error) {
|
||||
}
|
||||
// Valid field. Append index.
|
||||
path = append(path, field.name)
|
||||
if field.ss {
|
||||
if field.isSliceOfStructs && (!field.unmarshalerInfo.IsValid || (field.unmarshalerInfo.IsValid && field.unmarshalerInfo.IsSliceElement)) {
|
||||
// Parse a special case: slices of structs.
|
||||
// i+1 must be the slice index.
|
||||
//
|
||||
@ -142,7 +142,7 @@ func (c *cache) create(t reflect.Type, info *structInfo) *structInfo {
|
||||
c.create(ft, info)
|
||||
for _, fi := range info.fields[bef:len(info.fields)] {
|
||||
// exclude required check because duplicated to embedded field
|
||||
fi.required = false
|
||||
fi.isRequired = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,6 +162,7 @@ func (c *cache) createField(field reflect.StructField, info *structInfo) {
|
||||
// First let's get the basic type.
|
||||
isSlice, isStruct := false, false
|
||||
ft := field.Type
|
||||
m := isTextUnmarshaler(reflect.Zero(ft))
|
||||
if ft.Kind() == reflect.Ptr {
|
||||
ft = ft.Elem()
|
||||
}
|
||||
@ -178,29 +179,26 @@ func (c *cache) createField(field reflect.StructField, info *structInfo) {
|
||||
}
|
||||
}
|
||||
if isStruct = ft.Kind() == reflect.Struct; !isStruct {
|
||||
if conv := c.converter(ft); conv == nil {
|
||||
if c.converter(ft) == nil && builtinConverters[ft.Kind()] == nil {
|
||||
// Type is not supported.
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
info.fields = append(info.fields, &fieldInfo{
|
||||
typ: field.Type,
|
||||
name: field.Name,
|
||||
ss: isSlice && isStruct,
|
||||
alias: alias,
|
||||
anon: field.Anonymous,
|
||||
required: options.Contains("required"),
|
||||
typ: field.Type,
|
||||
name: field.Name,
|
||||
alias: alias,
|
||||
unmarshalerInfo: m,
|
||||
isSliceOfStructs: isSlice && isStruct,
|
||||
isAnonymous: field.Anonymous,
|
||||
isRequired: options.Contains("required"),
|
||||
})
|
||||
}
|
||||
|
||||
// converter returns the converter for a type.
|
||||
func (c *cache) converter(t reflect.Type) Converter {
|
||||
conv := c.regconv[t]
|
||||
if conv == nil {
|
||||
conv = c.conv[t.Kind()]
|
||||
}
|
||||
return conv
|
||||
return c.regconv[t]
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -219,12 +217,18 @@ func (i *structInfo) get(alias string) *fieldInfo {
|
||||
}
|
||||
|
||||
type fieldInfo struct {
|
||||
typ reflect.Type
|
||||
name string // field name in the struct.
|
||||
ss bool // true if this is a slice of structs.
|
||||
alias string
|
||||
anon bool // is an embedded field
|
||||
required bool // tag option
|
||||
typ reflect.Type
|
||||
// name is the field name in the struct.
|
||||
name string
|
||||
alias string
|
||||
// unmarshalerInfo contains information regarding the
|
||||
// encoding.TextUnmarshaler implementation of the field type.
|
||||
unmarshalerInfo unmarshaler
|
||||
// isSliceOfStructs indicates if the field type is a slice of structs.
|
||||
isSliceOfStructs bool
|
||||
// isAnonymous indicates whether the field is embedded in the struct.
|
||||
isAnonymous bool
|
||||
isRequired bool
|
||||
}
|
||||
|
||||
type pathPart struct {
|
||||
|
Reference in New Issue
Block a user