output

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: GPL-2.0, GPL-2.0-only Imports: 9 Imported by: 0

Documentation

Overview

Package output handles formatting and writing scan results to various output formats.

Package output handles formatting and writing scan results to various output formats.

Package output handles formatting and writing scan results to various output formats including JSON, SARIF, and HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CycloneDXWriter

type CycloneDXWriter struct {
	// PrettyPrint enables indented formatting. Default: true
	PrettyPrint bool

	// Indent specifies the indentation string. Default: "  " (2 spaces)
	Indent string
	// contains filtered or unexported fields
}

CycloneDXWriter implements the Writer interface for CycloneDX CBOM format. It converts interim format to CycloneDX 1.6 CBOM and validates the output.

func NewCycloneDXWriter

func NewCycloneDXWriter() *CycloneDXWriter

NewCycloneDXWriter creates a new CycloneDX writer with default settings.

func (*CycloneDXWriter) Write

func (w *CycloneDXWriter) Write(report *entities.InterimReport, destination string) error

Write converts the interim report to CycloneDX CBOM format and writes it.

The conversion process: 1. Transforms interim format to CycloneDX 1.6 BOM 2. Applies strict mapping (skips incomplete assets) 3. Validates against CycloneDX 1.6 schema 4. Writes to destination (stdout or file)

Destination handling:

  • "" (empty) or "-": Write to stdout
  • file path: Write to file with permissions 0600 (rw-------)

If writing to a file:

  • File will be overwritten if it exists
  • Parent directory must exist (returns error otherwise)

type JSONWriter

type JSONWriter struct {
	// PrettyPrint enables indented formatting. Default: true
	PrettyPrint bool

	// Indent specifies the indentation string. Default: "  " (2 spaces)
	Indent string
}

JSONWriter implements the Writer interface for JSON output format. It produces pretty-printed JSON with 2-space indentation.

func NewJSONWriter

func NewJSONWriter() *JSONWriter

NewJSONWriter creates a new JSON writer with default settings.

func (*JSONWriter) Write

func (w *JSONWriter) Write(report *entities.InterimReport, destination string) error

Write writes the interim report to JSON format.

Destination handling:

  • "" (empty) or "-": Write to stdout
  • file path: Write to file with permissions 0644 (rw-r--r--)

If writing to a file:

  • File will be overwritten if it exists
  • Parent directory must exist (returns error otherwise)

type Writer

type Writer interface {
	// Write formats and writes the report to the specified destination.
	//
	// The destination parameter determines where output is written:
	//   - "" (empty string): Write to stdout
	//   - "-": Write to stdout (Unix convention)
	//   - file path: Write to the specified file
	//
	// Parameters:
	//   - report: The scan results to write
	//   - destination: Output location (empty/"" for stdout, or file path)
	//
	// Returns an error if writing fails.
	Write(report *entities.InterimReport, destination string) error
}

Writer defines the interface for formatting and writing scan results to various output formats.

Implementations exist for:

  • JSON (default format)

type WriterFactory

type WriterFactory struct {
	// contains filtered or unexported fields
}

WriterFactory provides a registry of output format writers. It enables dynamic selection of output formats based on user input.

Example usage:

factory := output.NewWriterFactory()
writer, err := factory.GetWriter("json")
if err != nil {
    return err
}
writer.Write(report, "/path/to/output.json")

func NewWriterFactory

func NewWriterFactory() *WriterFactory

NewWriterFactory creates a factory with all supported output format writers registered.

Currently supported formats:

  • json: Standard JSON output (pretty-printed by default)
  • cyclonedx: CycloneDX 1.6 CBOM format

func (*WriterFactory) GetWriter

func (f *WriterFactory) GetWriter(format string) (Writer, error)

GetWriter returns the writer implementation for the specified format.

Parameters:

  • format: The output format name (e.g., "json", "csv", "html")

Returns:

  • Writer implementation for the format
  • Error if format is not supported

func (*WriterFactory) SupportedFormats

func (f *WriterFactory) SupportedFormats() []string

SupportedFormats returns a sorted list of all supported output format names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL