mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 07:10:41 -08:00
28 lines
536 B
Go
28 lines
536 B
Go
package report
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
// JSONWriter implements result Writer
|
|
type JSONWriter struct {
|
|
Output io.Writer
|
|
}
|
|
|
|
// Write writes the results in JSON format
|
|
func (jw JSONWriter) Write(results Results) error {
|
|
output, err := json.MarshalIndent(results, "", " ")
|
|
if err != nil {
|
|
return xerrors.Errorf("failed to marshal json: %w", err)
|
|
}
|
|
|
|
if _, err = fmt.Fprint(jw.Output, string(output)); err != nil {
|
|
return xerrors.Errorf("failed to write json: %w", err)
|
|
}
|
|
return nil
|
|
}
|