Snyk Golang CLI Plugin

2.1.1 · active · verified Wed Apr 22

The `snyk-go-plugin` package serves as a crucial plugin for the Snyk CLI, enabling it to detect and report known vulnerabilities within Golang projects. It specifically supports projects utilizing `dep` (via `Gopkg.lock`) or `govendor` (via `vendor/vendor.json`) for dependency management, as well as `go.mod` projects. The current stable version is 2.1.1, with releases occurring frequently, often monthly or bi-monthly, and sometimes more often for critical bug fixes. Its primary differentiator is its integration with the broader Snyk security platform, providing automated vulnerability scanning and remediation advice for Go applications, unlike standalone static analysis tools. It ships with TypeScript types, indicating strong support for modern JavaScript and TypeScript development workflows, and requires Node.js version 20 or higher.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `inspect` function to programmatically scan a Go project's dependencies and output the results, including how to configure options like PackageURL generation.

import { inspect } from 'snyk-go-plugin';
import * as path from 'path';

async function scanGoProject(projectDir: string) {
  try {
    console.log(`Scanning Go project in: ${projectDir}`);
    // The 'go.mod' file is often used as the manifest file, or Gopkg.lock/vendor/vendor.json
    const result = await inspect(
      projectDir,
      'go.mod',
      { 
        // Optionally disable PackageURL generation if not needed
        configuration: { includePackageUrls: true },
        // Other options can be passed here, e.g., debug: true
      }
    );
    console.log('Snyk Go Plugin inspection result:');
    console.dir(result, { depth: null });
    if (result.package.dependencies) {
        console.log(`Found ${Object.keys(result.package.dependencies).length} direct dependencies.`);
    }
  } catch (error) {
    console.error('Error during Snyk Go Plugin inspection:', error);
    process.exit(1);
  }
}

// Example usage: scan the current directory as a Go project
scanGoProject(process.cwd());

view raw JSON →