-
Notifications
You must be signed in to change notification settings - Fork 4
/
extractApiPaths.go
67 lines (60 loc) · 1.47 KB
/
extractApiPaths.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
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
// Function to get API paths based on domains
func getApiPaths(domains []string) {
// Prepare request data
endpoint := fmt.Sprintf("%s/apiPathfromDomain", 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
}
// Access and print API paths
if apiPaths, ok := response["apiPaths"].([]interface{}); ok {
for _, path := range apiPaths {
if pathStr, ok := path.(string); ok {
fmt.Println(pathStr)
} else {
fmt.Println("Error: Invalid type in 'apiPaths'")
}
}
}
}