gosec/report/junit/writer.go

27 lines
514 B
Go
Raw Normal View History

package junit
import (
"encoding/xml"
"io"
2021-05-20 09:16:42 +01:00
"github.com/securego/gosec/v2"
)
//WriteReport write a report in JUnit format to the output writer
2021-05-20 09:16:42 +01:00
func WriteReport(w io.Writer, data *gosec.ReportInfo) error {
junitXMLStruct := GenerateReport(data)
raw, err := xml.MarshalIndent(junitXMLStruct, "", "\t")
if err != nil {
return err
}
xmlHeader := []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
raw = append(xmlHeader, raw...)
_, err = w.Write(raw)
if err != nil {
return err
}
return nil
}