diff options
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/asn1/asn1.go | 2 | ||||
| -rw-r--r-- | src/encoding/asn1/marshal.go | 2 | ||||
| -rw-r--r-- | src/encoding/json/encode.go | 5 | ||||
| -rw-r--r-- | src/encoding/xml/typeinfo.go | 2 |
4 files changed, 5 insertions, 6 deletions
diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go index f9b9cb4930..cffc06dc9c 100644 --- a/src/encoding/asn1/asn1.go +++ b/src/encoding/asn1/asn1.go @@ -914,7 +914,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam structType := fieldType for i := 0; i < structType.NumField(); i++ { - if structType.Field(i).PkgPath != "" { + if !structType.Field(i).IsExported() { err = StructuralError{"struct contains unexported fields"} return } diff --git a/src/encoding/asn1/marshal.go b/src/encoding/asn1/marshal.go index 0d34d5aa1e..5b4d786d49 100644 --- a/src/encoding/asn1/marshal.go +++ b/src/encoding/asn1/marshal.go @@ -488,7 +488,7 @@ func makeBody(value reflect.Value, params fieldParameters) (e encoder, err error t := v.Type() for i := 0; i < t.NumField(); i++ { - if t.Field(i).PkgPath != "" { + if !t.Field(i).IsExported() { return nil, StructuralError{"struct contains unexported fields"} } } diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 483b9d8f2d..751f03d33d 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -1239,19 +1239,18 @@ func typeFields(t reflect.Type) structFields { // Scan f.typ for fields to include. for i := 0; i < f.typ.NumField(); i++ { sf := f.typ.Field(i) - isUnexported := sf.PkgPath != "" if sf.Anonymous { t := sf.Type if t.Kind() == reflect.Ptr { t = t.Elem() } - if isUnexported && t.Kind() != reflect.Struct { + if !sf.IsExported() && t.Kind() != reflect.Struct { // Ignore embedded fields of unexported non-struct types. continue } // Do not ignore embedded fields of unexported struct types // since they may have exported fields. - } else if isUnexported { + } else if !sf.IsExported() { // Ignore unexported non-embedded fields. continue } diff --git a/src/encoding/xml/typeinfo.go b/src/encoding/xml/typeinfo.go index f30fe58590..162724ef1a 100644 --- a/src/encoding/xml/typeinfo.go +++ b/src/encoding/xml/typeinfo.go @@ -60,7 +60,7 @@ func getTypeInfo(typ reflect.Type) (*typeInfo, error) { n := typ.NumField() for i := 0; i < n; i++ { f := typ.Field(i) - if (f.PkgPath != "" && !f.Anonymous) || f.Tag.Get("xml") == "-" { + if (!f.IsExported() && !f.Anonymous) || f.Tag.Get("xml") == "-" { continue // Private field } |
