csv.go 828 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package report
  2. import (
  3. "encoding/csv"
  4. "io"
  5. "strconv"
  6. )
  7. // writeCsv writes the list of findings to a writeCloser.
  8. func writeCsv(f []*Finding, w io.WriteCloser) error {
  9. if len(f) == 0 {
  10. return nil
  11. }
  12. defer w.Close()
  13. cw := csv.NewWriter(w)
  14. err := cw.Write([]string{"RuleID",
  15. "Commit",
  16. "File",
  17. "Secret",
  18. "Match",
  19. "StartLine",
  20. "EndLine",
  21. "StartColumn",
  22. "EndColumn",
  23. "Author",
  24. "Message",
  25. "Date",
  26. "Email",
  27. })
  28. if err != nil {
  29. return err
  30. }
  31. for _, f := range f {
  32. err = cw.Write([]string{f.RuleID,
  33. f.Commit,
  34. f.File,
  35. f.Secret,
  36. f.Match,
  37. strconv.Itoa(f.StartLine),
  38. strconv.Itoa(f.EndLine),
  39. strconv.Itoa(f.StartColumn),
  40. strconv.Itoa(f.EndColumn),
  41. f.Author,
  42. f.Message,
  43. f.Date,
  44. f.Email,
  45. })
  46. if err != nil {
  47. return err
  48. }
  49. }
  50. cw.Flush()
  51. return cw.Error()
  52. }