# core/plugins/code.go.plugin.ts

> 40 lines of code and 12 definitions.

Tree: GovLab Docs
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-plugins-code-go-plugin-ts
Source text: https://banes-lab.com/source/docs/core/plugins/code.go.plugin.ts.txt

Listed in [core/plugins](https://banes-lab.com/api/source/docs/core/plugins.md), before [core/plugins/code.typescript.plugin.ts](https://banes-lab.com/source/docs/core/plugins/code.typescript.plugin.ts.md).

## Definitions

- `analyze` (method_definition, line 25, exported)
- `isExcluded` (lexical_declaration, line 11)
- `isGoSource` (lexical_declaration, line 13)
- `makeRelPath` (lexical_declaration, line 17)
- `posix` (lexical_declaration, line 19)
- `analyzer` (lexical_declaration, line 24, exported)
- `files` (lexical_declaration, line 26, exported)
- `relPath` (lexical_declaration, line 30, exported)
- `index` (lexical_declaration, line 31, exported)
- `graph` (lexical_declaration, line 35, exported)
- `module` (lexical_declaration, line 36, exported)
- `canAnalyze` (method_definition, line 40, exported)

## Contained in

- [core/plugins](https://banes-lab.com/anatomy/docs/folder-docs-core-plugins.md)

## Uses

- [configuration/strings/code.strings.ts](https://banes-lab.com/source/docs/configuration/strings/code.strings.ts.md)

## Linked from

- [configuration/strings](https://banes-lab.com/anatomy/docs/folder-docs-configuration-strings.md)

## Source

```typescript
import { GO_MODULE_FILE, GO_SOURCE_SUFFIX, GO_TEST_SUFFIX } from "#configuration/constants/code.go.constants";
import { buildGoGraph, indexGoFiles } from "#core/analyzers/code.go.analyzer";
import type { Analyzer } from "#types/code.types";
import { ROOT } from "@ssot/paths";
import { excludeMatcher } from "@govlab/quality/config";
import { existsSync } from "node:fs";
import { goSummary } from "#configuration/strings/code.strings";
import { join } from "node:path";
import { walkFiles } from "#core/loaders/base.loader";

const isExcluded = await excludeMatcher(ROOT);

const isGoSource = function isGoSource(file: string): boolean {
    return file.endsWith(GO_SOURCE_SUFFIX) && !file.endsWith(GO_TEST_SUFFIX);
};

const makeRelPath = function makeRelPath(dirPosix: string): (file: string) => string {
    return (file: string): string => {
        const posix = file.split("\\").join("/");
        return posix.startsWith(dirPosix) ? posix.slice(dirPosix.length + 1) : posix;
    };
};

export const analyzer: Analyzer = {
    analyze(request) {
        const files = walkFiles(request.moduleDir, isExcluded).filter(isGoSource);
        if (files.length === 0) {
            return null;
        }
        const relPath = makeRelPath(request.moduleDir.split("\\").join("/"));
        const index = indexGoFiles(files);
        if (index.funcMap.size === 0) {
            return null;
        }
        const graph = buildGoGraph(index, relPath).result();
        const module = relPath(request.moduleDir) || request.moduleDir;
        request.logger?.(goSummary(module, index.funcMap.size, graph.nodes.length));
        return graph.nodes.length === 0 ? null : graph;
    },
    canAnalyze(dir) {
        return existsSync(join(dir, GO_MODULE_FILE));
    },
    ecosystem: "go",
};
```
