-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (54 loc) · 1.54 KB
/
main.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 (
"encoding/json"
"fmt"
"net/http"
)
type ChallengeResponse struct {
Follow string `json:"follow"`
Message string `json:"message"`
}
var prevFollow = ""
var requestCounter = 0
func main() {
url := "https://www.letsrevolutionizetesting.com/challenge"
processChallenge(url)
}
func processChallenge(url string) {
requestCounter++
fmt.Printf("Request #%d to %s\n", requestCounter, url)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println("Error creating HTTP request:", err)
return
}
req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making HTTP request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Println("HTTP request returned a non-OK status code:", resp.Status)
return
}
var response ChallengeResponse
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&response); err != nil {
fmt.Println("Error decoding JSON:", err)
return
}
// Check if Follow/ Message is empty
if response.Follow != "" {
fmt.Printf("Follow: %s\n", response.Follow)
prevFollow = response.Follow
} else {
fmt.Println("Change in response format, stopping recursion.")
fmt.Println("---------------")
fmt.Println("Message: ", response.Message)
return
}
processChallenge(response.Follow)
}