-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv.go
42 lines (38 loc) · 783 Bytes
/
csv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"encoding/csv"
"fmt"
"strings"
"github.com/google/go-github/github"
)
func generateCSV(issues []*github.Issue) {
records := generateIssueArray(issues)
if *filename != "" {
err := writeCSVToFIle(records)
if err != nil {
fmt.Println("Centrifuge Error: Could not write csv to file", err)
return
}
} else {
for _, v := range records {
fmt.Println(strings.Join(v, ","))
}
}
}
func writeCSVToFIle(records [][]string) error {
csvfile, err := createFile()
if err != nil {
return err
}
defer csvfile.Close()
writer := csv.NewWriter(csvfile)
for _, record := range records {
err := writer.Write(record)
if err != nil {
return err
}
}
fmt.Println("Data Successfully Written in: ", *filename)
writer.Flush()
return nil
}