-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
49 lines (38 loc) · 965 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
48
49
package main
import (
"net"
"strings"
"github.com/proximax-storage/go-xpx-chain-sdk/tools/health"
)
func insertSpaceIfExceedsLength(input string, maxLength int) string {
if len(input) > maxLength {
return input[:maxLength] + " " + input[maxLength:]
}
return input
}
// Checks if the input is a DNS name and abbreviates it if so.
func abbreviateIfDNSName(address string) string {
host, _, err := net.SplitHostPort(address)
if err != nil {
host = address
}
if ip := net.ParseIP(host); ip != nil {
return host
}
parts := strings.Split(host, ".")
if len(parts) > 0 {
return parts[0]
}
return address
}
func parseNodes(nodes []Node) ([]*health.NodeInfo, error) {
nodeInfos := make([]*health.NodeInfo, 0, len(nodes))
for _, node := range nodes {
ni, err := health.NewNodeInfo(node.IdentityKey, node.Endpoint, node.FriendlyName)
if err != nil {
return nil, err
}
nodeInfos = append(nodeInfos, ni)
}
return nodeInfos, nil
}