-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathassociatedips.go
35 lines (32 loc) · 1.04 KB
/
associatedips.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
package main
import (
"encoding/json"
"fmt"
"sync"
)
func associatedIPs(work chan string, wg *sync.WaitGroup) {
defer wg.Done()
for text := range work {
response := getResponse("GET", "company/"+text+"/associated-ips", "")
if output == "list" {
parseAndPrintIPs(response)
} else {
fmt.Println(response)
}
}
}
func parseAndPrintIPs(body string) {
var results map[string]interface{}
json.Unmarshal([]byte(body), &results)
val, ok := results["records"]
// Check if there are records in the request to avoid the interface conversion panic
if !ok || val == nil {
fmt.Println(body)
return
}
recordInterfaces := results["records"].([]interface{})
for _, record := range recordInterfaces {
recordMap := record.(map[string]interface{})
fmt.Println(recordMap["cidr"].(string))
}
}