-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
47 lines (43 loc) · 1.02 KB
/
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 gosrm
import (
"bytes"
"fmt"
"strings"
)
// convertSliceToStr converts a slice of anything to {v}{sep}{v} representation of the slice.
func convertSliceToStr(s any, sep string) string {
var b bytes.Buffer
switch slice := s.(type) {
case []uint16:
for _, n := range slice {
b.WriteString(fmt.Sprintf("%d%s", n, sep))
}
case []int64:
for _, n := range slice {
b.WriteString(fmt.Sprintf("%d%s", n, sep))
}
case []float32:
for _, f := range slice {
b.WriteString(fmt.Sprintf("%f%s", f, sep))
}
case []string:
for _, s := range slice {
b.WriteString(s + sep)
}
case []Approaches:
for _, approach := range slice {
b.WriteString(string(approach) + sep)
}
case []Bearing:
for _, bearing := range slice {
b.WriteString(fmt.Sprintf("%d,%d%s", bearing.Value, bearing.Range, sep))
}
case []Coordinate:
for _, coor := range slice {
b.WriteString(fmt.Sprintf("%f,%f%s", coor[0], coor[1], sep))
}
default:
panic("unsupported type")
}
return strings.TrimSuffix(b.String(), sep)
}