Properly handle optional query string
When its type is an alias.
@@ -287,6 +287,7 @@ func InitStructFields(args []*InitArgData, targetVar, sourcePkg, targetPkg strin
t := scope.GoFullTypeRef(&expr.AttributeExpr{Type: arg.FieldType}, targetPkg)
cast := fmt.Sprintf("%s(%s)", t, arg.Name)
if arg.Pointer {
+ code += "if " + arg.Name + " != nil {\n"
cast = fmt.Sprintf("%s(*%s)", t, arg.Name)
}
if arg.FieldPointer {
@@ -296,6 +297,9 @@ func InitStructFields(args []*InitArgData, targetVar, sourcePkg, targetPkg strin
} else {
code += fmt.Sprintf("%s := %s\n", targetVar, cast)
}
+ if arg.Pointer {
+ code += "}\n"
+ }
default:
srcctx := NewAttributeContext(arg.Pointer, false, true, sourcePkg, scope)
tgtctx := NewAttributeContext(arg.FieldPointer, false, true, targetPkg, scope)
