forked from mirror/redis
Fix cleanup
This commit is contained in:
parent
8926f2992a
commit
380ab17274
|
@ -29,12 +29,12 @@ func newStructMap() *structMap {
|
||||||
|
|
||||||
func (s *structMap) get(t reflect.Type) *structFields {
|
func (s *structMap) get(t reflect.Type) *structFields {
|
||||||
if v, ok := s.m.Load(t); ok {
|
if v, ok := s.m.Load(t); ok {
|
||||||
return m.(*structFields), ok
|
return v.(*structFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
fMap := getStructFields(v, "redis")
|
fMap := getStructFields(t, "redis")
|
||||||
s.m.Store(t, fMap)
|
s.m.Store(t, fMap)
|
||||||
return fmap, true
|
return fMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStructFields() *structFields {
|
func newStructFields() *structFields {
|
||||||
|
@ -52,19 +52,16 @@ func (s *structFields) get(tag string) (*structField, bool) {
|
||||||
return f, ok
|
return f, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStructFields(ob reflect.Value, fieldTag string) *structFields {
|
func getStructFields(t reflect.Type, fieldTag string) *structFields {
|
||||||
var (
|
var (
|
||||||
num = ob.NumField()
|
num = t.NumField()
|
||||||
out = newStructFields()
|
out = newStructFields()
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
f := ob.Field(i)
|
f := t.Field(i)
|
||||||
if !f.IsValid() || !f.CanSet() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tag := ob.Type().Field(i).Tag.Get(fieldTag)
|
tag := t.Field(i).Tag.Get(fieldTag)
|
||||||
if tag == "" || tag == "-" {
|
if tag == "" || tag == "-" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -75,7 +72,7 @@ func getStructFields(ob reflect.Value, fieldTag string) *structFields {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the built-in decoder.
|
// Use the built-in decoder.
|
||||||
out.set(tag, &structField{index: i, fn: decoders[f.Kind()]})
|
out.set(tag, &structField{index: i, fn: decoders[f.Type.Kind()]})
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
Loading…
Reference in New Issue