github.com/seilagamo/poc-lava-release@v0.3.3-rc3/internal/report/jsonprinter.go (about)

     1  // Copyright 2023 Adevinta
     2  
     3  package report
     4  
     5  import (
     6  	"encoding/json"
     7  	"fmt"
     8  	"io"
     9  )
    10  
    11  // jsonPrinter represents a JSON report printer.
    12  type jsonPrinter struct{}
    13  
    14  // Print renders the scan results in JSON format.
    15  func (prn jsonPrinter) Print(w io.Writer, vulns []vulnerability, _ summary) error {
    16  	enc := json.NewEncoder(w)
    17  	enc.SetIndent("", "  ")
    18  	if err := enc.Encode(vulns); err != nil {
    19  		return fmt.Errorf("encode report: %w", err)
    20  	}
    21  	return nil
    22  }