Files
aquasecurity-trivy/pkg/report/k8s/json.go
Jose Donizetti 029dd76c30 feat: add k8s subcommand (#2065)
Co-authored-by: knqyf263 <knqyf263@gmail.com>
2022-05-12 21:11:29 +03:00

27 lines
493 B
Go

package k8s
import (
"encoding/json"
"fmt"
"io"
"golang.org/x/xerrors"
)
type JSONWriter struct {
Output io.Writer
}
// Write writes the results in JSON format
func (jw JSONWriter) Write(report Report) error {
output, err := json.MarshalIndent(report, "", " ")
if err != nil {
return xerrors.Errorf("failed to marshal json: %w", err)
}
if _, err = fmt.Fprintln(jw.Output, string(output)); err != nil {
return xerrors.Errorf("failed to write json: %w", err)
}
return nil
}