-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
43 lines (37 loc) · 762 Bytes
/
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
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from %s!", os.Getenv("SERVICE_NAME"))
}
func main() {
url := os.Getenv("TARGET_URL")
if url == "" {
log.Fatal("TARGET_URL environment variable is not set")
}
port := os.Getenv("PORT")
if port == "" {
log.Fatal("PORT environment variable is not set")
}
http.HandleFunc("/", handler)
go func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}()
for {
resp, err := http.Get(url)
if err != nil {
log.Println("Error:", err)
} else {
body, _ := io.ReadAll(resp.Body)
log.Println("Response:", string(body))
resp.Body.Close()
}
time.Sleep(5 * time.Second)
}
}