MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract

Function extract

src/resolution/frameworks/goframe.ts:67–110  ·  view source on GitHub ↗
(filePath, content)

Source from the content-addressed store, hash-verified

65 },
66
67 extract(filePath, content) {
68 if (!filePath.endsWith('.go')) return { nodes: [], references: [] };
69 // Cheap reject: the file must mention g.Meta at all.
70 if (!content.includes('g.Meta')) return { nodes: [], references: [] };
71
72 const nodes: Node[] = [];
73 const now = Date.now();
74 const safe = stripCommentsForRegex(content, 'go');
75 const pkg = GO_PACKAGE_RE.exec(safe)?.[1];
76
77 GOFRAME_META_RE.lastIndex = 0;
78 let match: RegExpExecArray | null;
79 while ((match = GOFRAME_META_RE.exec(safe)) !== null) {
80 const [, requestType, tag] = match;
81 const pathMatch = META_PATH_RE.exec(tag!);
82 if (!pathMatch) continue; // response `g.Meta `mime:…`` and other non-route metadata
83 const routePath = pathMatch[1]!;
84 const methodMatch = META_METHOD_RE.exec(tag!);
85 // GoFrame defaults to all methods when `method:` is omitted.
86 const method = methodMatch ? methodMatch[1]!.toUpperCase() : 'ANY';
87 const line = safe.slice(0, match.index).split('\n').length;
88 // The handler's signature qualifies the request type with its package
89 // (`req *cash.ListReq`); encode `pkg.Type` so the synthesizer can match it.
90 const joinKey = pkg ? `${pkg}.${requestType}` : requestType!;
91
92 nodes.push({
93 id: `route:${filePath}:${line}:${method}:${routePath}`,
94 kind: 'route',
95 name: `${method} ${routePath}`,
96 // The request type is the synthesizer's join key — encode it after the
97 // marker. The path stays human-readable in `name`.
98 qualifiedName: `${filePath}${GOFRAME_ROUTE_MARKER}${joinKey}`,
99 filePath,
100 startLine: line,
101 endLine: line,
102 startColumn: 0,
103 endColumn: match[0].length,
104 language: 'go',
105 updatedAt: now,
106 });
107 }
108
109 return { nodes, references: [] };
110 },
111
112 // The route → controller-method edge is reflective (request-type join across
113 // files) and is built by the `goframeRouteEdges` synthesizer after the graph

Callers

nothing calls this directly

Calls 3

stripCommentsForRegexFunction · 0.90
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected