forked from rashahacks/jsmon-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewUrls.go
53 lines (45 loc) · 1.04 KB
/
viewUrls.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
type URLResponse struct {
Urls []URLItem `json:"urls"`
Message string `json:"Message"`
}
type URLItem struct {
URL string `json:"url"`
}
func viewUrls(size int) {
endpoint := fmt.Sprintf("%s/searchAllUrls?size=%d&start=0", apiBaseURL, size) // Use the size parameter
client := &http.Client{}
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("X-Jsmon-Key", strings.TrimSpace(getAPIKey()))
resp, err := client.Do(req)
if err != nil {
fmt.Printf("failed to send request: %v", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("failed to read response body: %v", err)
return
}
var response URLResponse
err = json.Unmarshal(body, &response)
if err != nil {
fmt.Printf("failed to unmarshal JSON response: %v", err)
return
}
for _, urlItem := range response.Urls {
fmt.Println(urlItem.URL)
}
}