-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
47 lines (43 loc) · 968 Bytes
/
utils.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
43
44
45
46
47
package builder
import (
"bytes"
"strconv"
)
func interfaceToString(input_int []interface{}) []string {
length := len(input_int)
columns := make([]string, length)
for index, element := range input_int {
columns[index] = convertValueToString(element)
}
return columns
}
func convertValueToString(value interface{}) string {
var result string
switch value := value.(type) {
case int:
result = strconv.Itoa(int(value))
case float64:
result = strconv.FormatFloat(value, 'f', 6, 64)
case string:
result = value
case []int:
var res bytes.Buffer
for index, el := range value {
res.WriteString(strconv.Itoa(int(el)))
if index != len(value)-1 {
res.WriteString(", ")
}
}
result = res.String()
case []float64:
var res bytes.Buffer
for index, el := range value {
res.WriteString(strconv.FormatFloat(el, 'f', 6, 64))
if index != len(value)-1 {
res.WriteString(", ")
}
}
result = res.String()
}
return result
}