From 380ab17274cf3f82dffefa02b8c37cbe59e9aa0d Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 29 Jan 2021 12:12:47 +0200 Subject: [PATCH] Fix cleanup --- internal/hscan/structmap.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/internal/hscan/structmap.go b/internal/hscan/structmap.go index d66f76f..06d5d2f 100644 --- a/internal/hscan/structmap.go +++ b/internal/hscan/structmap.go @@ -29,12 +29,12 @@ func newStructMap() *structMap { func (s *structMap) get(t reflect.Type) *structFields { 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) - return fmap, true + return fMap } func newStructFields() *structFields { @@ -52,19 +52,16 @@ func (s *structFields) get(tag string) (*structField, bool) { return f, ok } -func getStructFields(ob reflect.Value, fieldTag string) *structFields { +func getStructFields(t reflect.Type, fieldTag string) *structFields { var ( - num = ob.NumField() + num = t.NumField() out = newStructFields() ) for i := 0; i < num; i++ { - f := ob.Field(i) - if !f.IsValid() || !f.CanSet() { - continue - } + f := t.Field(i) - tag := ob.Type().Field(i).Tag.Get(fieldTag) + tag := t.Field(i).Tag.Get(fieldTag) if tag == "" || tag == "-" { continue } @@ -75,7 +72,7 @@ func getStructFields(ob reflect.Value, fieldTag string) *structFields { } // 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