MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / loadGoModule

Function loadGoModule

src/resolution/go-module.ts:30–47  ·  view source on GitHub ↗
(projectRoot: string)

Source from the content-addressed store, hash-verified

28 * a follow-up if a real repro shows up.
29 */
30export function loadGoModule(projectRoot: string): GoModule | null {
31 const goModPath = path.join(projectRoot, 'go.mod');
32 let content: string;
33 try {
34 content = fs.readFileSync(goModPath, 'utf-8');
35 } catch {
36 return null;
37 }
38 // `module <path>` is the first non-comment directive in any valid go.mod.
39 // Strip line comments so a `// module foo` doesn't false-match.
40 const stripped = content.replace(/\/\/[^\n]*/g, '');
41 const match = stripped.match(/^\s*module\s+(\S+)\s*$/m);
42 if (!match) return null;
43 // Strip optional quoting around the module path.
44 const modulePath = match[1]!.replace(/^["']|["']$/g, '');
45 if (!modulePath) return null;
46 return { modulePath, rootDir: projectRoot };
47}

Callers 1

createContextMethod · 0.90

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected