-
Notifications
You must be signed in to change notification settings - Fork 314
Expand file tree
/
Copy pathSubscribe.go
More file actions
47 lines (44 loc) · 752 Bytes
/
Subscribe.go
File metadata and controls
47 lines (44 loc) · 752 Bytes
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
package main
import (
"fmt"
"io"
"net/http"
"time"
)
func Subscribe(url string) string {
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error:", err)
return ""
}
defer resp.Body.Close()
readAll, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return ""
}
return string(readAll)
}
func subscribeUpdate(url string) {
defer func() {
if r := recover(); r != nil {
go subscribeUpdate(url)
}
}()
for {
time.Sleep(30 * time.Second)
subUrl := Subscribe(url)
if len(subUrl) > 0 {
if *detectLocation {
location := GetHttpLocation(subUrl)
if len(location) > 0 {
TargetUrl = location
} else {
TargetUrl = subUrl
}
} else {
TargetUrl = subUrl
}
}
}
}