forked from rancher/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.go
55 lines (48 loc) · 986 Bytes
/
format.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
48
49
50
51
52
53
54
55
package cmd
import (
"bytes"
"encoding/json"
"fmt"
)
func FormatEndpoint(data interface{}) string {
dataSlice, ok := data.([]interface{})
if !ok {
return ""
}
buf := &bytes.Buffer{}
for _, value := range dataSlice {
dataMap, ok := value.(map[string]interface{})
if !ok {
return ""
}
s := fmt.Sprintf("%v:%v", dataMap["ipAddress"], dataMap["port"])
if buf.Len() == 0 {
buf.WriteString(s)
} else {
buf.WriteString(", ")
buf.WriteString(s)
}
}
return buf.String()
}
func FormatIPAddresses(data interface{}) string {
//todo: revisit
return ""
//ips, ok := data.([]client.IpAddress)
//if !ok {
// return ""
//}
//
//ipStrings := []string{}
//for _, ip := range ips {
// if ip.Address != "" {
// ipStrings = append(ipStrings, ip.Address)
// }
//}
//
//return strings.Join(ipStrings, ", ")
}
func FormatJSON(data interface{}) (string, error) {
bytes, err := json.MarshalIndent(data, "", " ")
return string(bytes) + "\n", err
}