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

Function goPackageReader

src/graph/go-package.ts:43–67  ·  view source on GitHub ↗
(projectRoot: string)

Source from the content-addressed store, hash-verified

41 * A file it cannot read declares no package, so the qualifier does not match.
42 */
43export function goPackageReader(projectRoot: string): GoPackageOf {
44 const cache = new Map<string, string | null>();
45 return (filePath) => {
46 const hit = cache.get(filePath);
47 if (hit !== undefined) return hit;
48 let pkg: string | null = null;
49 const absPath = validatePathWithinRoot(projectRoot, filePath);
50 if (absPath) {
51 try {
52 const fd = openSync(absPath, 'r');
53 try {
54 const buf = Buffer.alloc(HEAD_BYTES);
55 const n = readSync(fd, buf, 0, HEAD_BYTES, 0);
56 pkg = goPackageClause(buf.toString('utf8', 0, n));
57 } finally {
58 closeSync(fd);
59 }
60 } catch {
61 pkg = null;
62 }
63 }
64 cache.set(filePath, pkg);
65 return pkg;
66 };
67}

Callers 1

goPackageReaderForFunction · 0.85

Calls 4

validatePathWithinRootFunction · 0.90
goPackageClauseFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected