From faa3dcf46a17bebd43a437edad21d26156e0e76f Mon Sep 17 00:00:00 2001 From: Tao Wen Date: Tue, 19 Sep 2017 10:06:34 +0800 Subject: [PATCH] do not report error when field is unexported --- feature_reflect_extension.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/feature_reflect_extension.go b/feature_reflect_extension.go index 508aef2..74f4b8b 100644 --- a/feature_reflect_extension.go +++ b/feature_reflect_extension.go @@ -227,9 +227,6 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err bindings := []*Binding{} for i := 0; i < typ.NumField(); i++ { field := typ.Field(i) - if unicode.IsLower([]rune(field.Name)[0]) { - continue - } tag := field.Tag.Get(cfg.getTagKey()) tagParts := strings.Split(tag, ",") if tag == "-" { @@ -272,7 +269,7 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err if decoder == nil { var err error decoder, err = decoderOfType(cfg, field.Type) - if err != nil { + if len(fieldNames) > 0 && err != nil { return nil, err } } @@ -280,11 +277,11 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err if encoder == nil { var err error encoder, err = encoderOfType(cfg, field.Type) - if err != nil { + if len(fieldNames) > 0 && err != nil { return nil, err } // map is stored as pointer in the struct - if field.Type.Kind() == reflect.Map { + if encoder != nil && field.Type.Kind() == reflect.Map { encoder = &optionalEncoder{encoder} } }