mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
33 lines
737 B
Go
33 lines
737 B
Go
package poweruser
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
)
|
|
|
|
// JSONPresenter is a JSON presentation object for the syft results
|
|
type JSONPresenter struct {
|
|
config JSONDocumentConfig
|
|
}
|
|
|
|
// NewJSONPresenter creates a new JSON presenter object for the given cataloging results.
|
|
func NewJSONPresenter(config JSONDocumentConfig) *JSONPresenter {
|
|
return &JSONPresenter{
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
// Present the PackageCatalog results to the given writer.
|
|
func (p *JSONPresenter) Present(output io.Writer) error {
|
|
doc, err := NewJSONDocument(p.config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
enc := json.NewEncoder(output)
|
|
// prevent > and < from being escaped in the payload
|
|
enc.SetEscapeHTML(false)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(&doc)
|
|
}
|