csv.go 897 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "SymlinkFile",
  18. "Secret",
  19. "Match",
  20. "StartLine",
  21. "EndLine",
  22. "StartColumn",
  23. "EndColumn",
  24. "Author",
  25. "Message",
  26. "Date",
  27. "Email",
  28. "Fingerprint",
  29. })
  30. if err != nil {
  31. return err
  32. }
  33. for _, f := range f {
  34. err = cw.Write([]string{f.RuleID,
  35. f.Commit,
  36. f.File,
  37. f.SymlinkFile,
  38. f.Secret,
  39. f.Match,
  40. strconv.Itoa(f.StartLine),
  41. strconv.Itoa(f.EndLine),
  42. strconv.Itoa(f.StartColumn),
  43. strconv.Itoa(f.EndColumn),
  44. f.Author,
  45. f.Message,
  46. f.Date,
  47. f.Email,
  48. f.Fingerprint,
  49. })
  50. if err != nil {
  51. return err
  52. }
  53. }
  54. cw.Flush()
  55. return cw.Error()
  56. }