Skip to content

Instantly share code, notes, and snippets.

@dele454
Created August 6, 2022 03:34
Show Gist options
  • Save dele454/03b5d6db27c12d8f10c0857a185a79d6 to your computer and use it in GitHub Desktop.
Save dele454/03b5d6db27c12d8f10c0857a185a79d6 to your computer and use it in GitHub Desktop.
Part 1 - CSV Transformation
// WriteReportToStdOut writes report to stdout
func (t *TransformationReporter) WriteReportToStdOut(ctx context.Context) error {
var err error
path := utils.RootDir()
// create template
tmpl, err := template.Must(template.New("STDOUT"), err).
ParseFiles(path + "/internal/transform/template/report.tmpl")
if err != nil {
return err
}
// apply tmpl to data
var processed bytes.Buffer
err = tmpl.ExecuteTemplate(&processed, "report.tmpl", t)
if err != nil {
return err
}
// write output to stdout
w := bufio.NewWriter(os.Stdout)
_, err = w.WriteString(processed.String())
if err != nil {
return err
}
// flush buffer
err = w.Flush()
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment