* Extract a mapping from (structName, jsonFieldName) to generated Go field * metadata so wrapper code can reference emitted field names and nil behavior.
(generatedTypeCode: string)
| 344 | * metadata so wrapper code can reference emitted field names and nil behavior. |
| 345 | */ |
| 346 | function extractFields(generatedTypeCode: string): Map<string, Map<string, GoExtractedField>> { |
| 347 | const result = new Map<string, Map<string, GoExtractedField>>(); |
| 348 | const structRe = /^type\s+(\w+)\s+struct\s*\{([^}]*)\}/gm; |
| 349 | let sm; |
| 350 | while ((sm = structRe.exec(generatedTypeCode)) !== null) { |
| 351 | const [, structName, body] = sm; |
| 352 | const fields = new Map<string, GoExtractedField>(); |
| 353 | const fieldRe = /^\s+(\w+)\s+([^\s`]+)\s+`json:"([^",]+)/gm; |
| 354 | let fm; |
| 355 | while ((fm = fieldRe.exec(body)) !== null) { |
| 356 | fields.set(fm[3], { name: fm[1], type: fm[2] }); |
| 357 | } |
| 358 | result.set(structName, fields); |
| 359 | } |
| 360 | return result; |
| 361 | } |
| 362 | |
| 363 | function goTypeIsPointer(goType: string | undefined): boolean { |
| 364 | return goType?.startsWith("*") ?? false; |
no test coverage detected
searching dependent graphs…