summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gorilla/schema/cache.go
diff options
context:
space:
mode:
authorDuco van Amstel <helcaraxan@gmail.com>2018-11-18 17:55:05 +0000
committerWim <wim@42.be>2018-11-25 21:21:04 +0100
commit09875fe1603307080f3a4172985c5dca3bd9912d (patch)
treea23220772f6f6597d509ca71b2df3480a77b8076 /vendor/github.com/gorilla/schema/cache.go
parentf716b8fc0ff90f47b61e218ef34019b38bd70e0d (diff)
downloadmatterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.tar.gz
matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.tar.bz2
matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.zip
Update direct dependencies where possible
Diffstat (limited to 'vendor/github.com/gorilla/schema/cache.go')
-rw-r--r--vendor/github.com/gorilla/schema/cache.go54
1 files changed, 29 insertions, 25 deletions
diff --git a/vendor/github.com/gorilla/schema/cache.go b/vendor/github.com/gorilla/schema/cache.go
index b2c5995d..73b75f48 100644
--- a/vendor/github.com/gorilla/schema/cache.go
+++ b/vendor/github.com/gorilla/schema/cache.go
@@ -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 {