github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/format/github/encoder.go (about) 1 package github 2 3 import ( 4 "encoding/json" 5 "io" 6 7 "github.com/anchore/syft/syft/format/github/internal/model" 8 "github.com/anchore/syft/syft/sbom" 9 ) 10 11 const ID sbom.FormatID = "github-json" 12 13 type encoder struct { 14 } 15 16 func NewFormatEncoder() sbom.FormatEncoder { 17 return encoder{} 18 } 19 20 func (e encoder) ID() sbom.FormatID { 21 return ID 22 } 23 24 func (e encoder) Aliases() []string { 25 return []string{ 26 "github", 27 } 28 } 29 30 func (e encoder) Version() string { 31 return sbom.AnyVersion 32 } 33 34 func (e encoder) Encode(writer io.Writer, s sbom.SBOM) error { 35 bom := model.ToGithubModel(&s) 36 37 enc := json.NewEncoder(writer) 38 enc.SetEscapeHTML(false) 39 enc.SetIndent("", " ") 40 41 return enc.Encode(bom) 42 }