Map support added for CSV exporter
This commit is contained in:
parent
8fe194bd10
commit
679fd8ab7a
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// CSVExporter exports response data as CSV streaming file
|
||||
@ -42,11 +43,12 @@ func (e *CSVExporter) Export(exports chan interface{}) {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
values = append(values, fmt.Sprint(val.Index(i)))
|
||||
}
|
||||
//case reflect.Map:
|
||||
// iter := val.MapRange()
|
||||
// for iter.Next() {
|
||||
// values = append(values, fmt.Sprint(iter.Value()))
|
||||
// }
|
||||
case reflect.Map:
|
||||
iter := val.MapRange()
|
||||
for iter.Next() {
|
||||
values = append(values, fmt.Sprint(iter.Value()))
|
||||
}
|
||||
sort.Strings(values)
|
||||
}
|
||||
if err := writer.Write(values); err != nil {
|
||||
log.Printf("CSV writing error on exporter: %v\n", err)
|
||||
|
@ -7,10 +7,11 @@ func TestCSVExporter_Export(t *testing.T) {
|
||||
defer close(ch)
|
||||
|
||||
exporter := &CSVExporter{
|
||||
FileName: "test.out",
|
||||
FileName: "out.csv",
|
||||
Comma: ';',
|
||||
}
|
||||
go exporter.Export(ch)
|
||||
|
||||
ch <- []string{"1", "2"}
|
||||
ch <- map[string]string{"key1": "value1", "key2": "value2"}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ func TestJSONExporter_Export(t *testing.T) {
|
||||
defer close(ch)
|
||||
|
||||
exporter := &JSONExporter{
|
||||
FileName: "test.json",
|
||||
FileName: "out.json",
|
||||
Indent: " ",
|
||||
}
|
||||
go exporter.Export(ch)
|
||||
|
Loading…
x
Reference in New Issue
Block a user