forked from rashahacks/jsmon-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDomainUrls.go
79 lines (70 loc) · 1.78 KB
/
getDomainUrls.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
// Function to get domain URLs
func getDomainUrls(domains []string) {
endpoint := fmt.Sprintf("%s/getDomainsUrls", apiBaseURL)
requestBody, err := json.Marshal(map[string]interface{}{
"domains": domains,
})
if err != nil {
fmt.Printf("Failed to marshal request body: %v\n", err)
return
}
// Create request
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(requestBody))
if err != nil {
fmt.Printf("Failed to create request: %v\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Jsmon-Key", strings.TrimSpace(getAPIKey()))
// Send request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Failed to send request: %v\n", err)
return
}
defer resp.Body.Close()
// Read response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Failed to read response body: %v\n", err)
return
}
// Parse response
var response map[string]interface{}
err = json.Unmarshal(body, &response)
if err != nil {
fmt.Printf("Failed to unmarshal JSON response: %v\n", err)
return
}
// Extract data
if data, ok := response["data"].(map[string]interface{}); ok {
// Print extracted domains
if extractedDomains, ok := data["extractedDomains"].([]interface{}); ok {
for _, domain := range extractedDomains {
if domainStr, ok := domain.(string); ok {
fmt.Println(domainStr)
}
}
}
// Print extracted URLs
if extractedUrls, ok := data["extractedUrls"].([]interface{}); ok {
for _, url := range extractedUrls {
if urlStr, ok := url.(string); ok {
fmt.Println(urlStr)
}
}
}
} else {
fmt.Println("Error: 'data' field not found or not in expected format")
}
}