in packages/jsii-pacmak/lib/targets/go/types/go-type-reference.ts [222:261]
public scopedTypeName(
typeMap: TypeMap,
scope: Package,
asRef = false,
): string {
if (typeMap.type === 'primitive') {
const { value } = typeMap;
const prefix = asRef && value !== 'interface{}' ? '*' : '';
return `${prefix}${value}`;
} else if (typeMap.type === 'array' || typeMap.type === 'map') {
const prefix = asRef ? '*' : '';
const wrapper = typeMap.type === 'array' ? '[]' : 'map[string]';
const innerName =
this.scopedTypeName(typeMap.value.typeMap, scope, asRef) ??
'interface{}';
return `${prefix}${wrapper}${innerName}`;
} else if (typeMap.type === 'interface') {
const prefix = asRef && typeMap.value.datatype ? '*' : '';
const baseName = typeMap.value.name;
// type is defined in the same scope as the current one, no namespace required
if (scope.packageName === typeMap.value.namespace && baseName) {
// if the current scope is the same as the types scope, return without a namespace
return `${prefix}${baseName}`;
}
// type is defined in another module and requires a namespace and import
if (baseName) {
return `${prefix}${typeMap.value.namespace}.${baseName}`;
}
} else if (typeMap.type === 'union') {
return 'interface{}';
} else if (typeMap.type === 'void') {
return '';
}
// type isn't handled
throw new Error(
`Type ${typeMap.value?.name} does not resolve to a known Go type.`,
);
}