Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHeader ¶
func CreateHeader(v interface{}) []string
CreateHeader uses the "csv" struct tags to build the CSV header v should be a struct with "csv" tags. Example:
type MyData struct { Field1 string `csv:"field_1"` IgnoreMe chan int `csv:"-"` Field2 time.Time `csv:"field_2"` }
CreateHeader(MyData{}) will output []string{"field_1", "field_2"}, ignoring the "-" tag.
Experimental
func MarshalCSV ¶
func MarshalCSV(v interface{}) []string
MarshalCSV returns the struct values as a slice of strings. Fields with the tag `csv:"-"` will be ignored.
Experimental
func SetDateTimeFormat ¶
func SetDateTimeFormat(format string)
SetDateTimeFormat updates the default format string to the supplied string. Valid formats: https://golang.org/src/time/format.go This is only used by MarshalCSV.
Types ¶
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter provides functionality for generating CSV-formatted reports using any struct that implements the Row interface.
func NewWithoutHeader ¶
NewWithoutHeader returns a pointer to a Reporter that will not include headers in the output
func (*Reporter) Flush ¶
Flush calls the same method in Reporter's underlying csv.Writer, then checks for and returns any errors
type Row ¶
type Row interface { // Header should return a list of the column names to be included in the CSV report Header() []string // Marshal should return a list of the data points to be written to the CSV report Marshal() []string }
Row provides the methods needed to convert a struct to a CSV row
Example (using experimental reporter.CreateHeader() and reporter.MarshalCSV()):
type MyData struct { Field1 string `csv:"field_1"` Field2 time.Time `csv:"field_2"` } func (d *MyData) Header() []string { return reporter.CreateHeader(d) } func (d *MyData) Marshal() []string { return reporter.MarshalCSV(d) }