-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_util.go
More file actions
32 lines (28 loc) · 819 Bytes
/
csv_util.go
File metadata and controls
32 lines (28 loc) · 819 Bytes
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
package search
import (
"reflect"
"strconv"
"strings"
)
func ToCsv(fields []string, r interface{}, total int64, embedField string, opts ...map[string]int) (out string) {
val := reflect.ValueOf(r)
models := reflect.Indirect(val)
if models.Len() == 0 {
return "0"
}
var rows []string
rows = append(rows, strconv.FormatInt(total, 10))
rows = BuildCsv(rows, fields, models, embedField, opts...)
return strings.Join(rows, "\n")
}
func ToNextCsv(fields []string, r interface{}, nextPageToken string, embedField string, opts ...map[string]int) (out string) {
val := reflect.ValueOf(r)
models := reflect.Indirect(val)
if models.Len() == 0 {
return "0"
}
var rows []string
rows = append(rows, nextPageToken)
rows = BuildCsv(rows, fields, models, embedField, opts...)
return strings.Join(rows, "\n")
}