-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (46 loc) · 1.06 KB
/
Copy pathmain.go
File metadata and controls
57 lines (46 loc) · 1.06 KB
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
package main
import (
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
fmt.Printf("Error loading .env file: %s\n", err)
return
}
hostsEnv := os.Getenv("HOSTS")
params := os.Getenv("PARAMS")
methodEnv := os.Getenv("METHOD")
if hostsEnv == "" || params == "" {
fmt.Println("Check the env!")
return
}
hosts := strings.Split(hostsEnv, ",")
for {
fmt.Println("============Starting to hit endpoints============")
for _, host := range hosts {
url := fmt.Sprintf("http://%s/channel/empty?%s", host, params)
client := &http.Client{}
req, err := http.NewRequest(methodEnv, url, nil)
if err != nil {
fmt.Println(err)
return
}
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
fmt.Printf("\nResponse Code from %s : %v \n\n", url, res.StatusCode)
fmt.Println("====================================")
}
fmt.Println("All endpoints hit. Waiting for 10 seconds...")
time.Sleep(10 * time.Second)
}
}