From bf7e45439b044d18d0fdf3151fbdd7994875edce Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Wed, 1 Dec 2021 22:06:06 +0000 Subject: [PATCH] engine: util: Skip unexported fields in struct field mapping Unexported fields should be ignored when mapping structs from Golang to mcl, as this avoids issues where certain structs cannot be used in mcl representation due to their structure that may be incompatible with conversion. Disallowing private fields allows those to still be included in the struct but ignored when mapping the types, allowing the mcl representation of the type to stil be valid Resolves: https://github.com/purpleidea/mgmt/issues/684 Signed-off-by: Joe Groocock --- engine/util/util.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/engine/util/util.go b/engine/util/util.go index f1d3e445..63029dd7 100644 --- a/engine/util/util.go +++ b/engine/util/util.go @@ -276,6 +276,13 @@ func StructKindToFieldNameTypeMap(kind string) (map[string]*types.Type, error) { // continue //} + // Skip unexported fields. These should never be mapped golang<->mcl. + // TODO: Use StructField.IsExported() in golang 1.17 + //if !field.IsExported() { + if field.PkgPath != "" { + continue + } + typ, err := types.TypeOf(field.Type) // some types (eg complex64) aren't convertible, so skip for now... if err != nil {