-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
66 lines (58 loc) · 1.37 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
package main
import (
"log"
"net/http"
"net/url"
"github.com/zserge/lorca"
)
const html = `
<html>
<head>
<title>Check URL</title>
</head>
<body>
url: <input id="url" value="https://fosdem.org"></input>
<button id="check" onclick="checkURL(document.getElementById('url').value)">Check</button>
<div id="status"></div>
</body>
</html>
`
func main() {
ui, err := lorca.New("data:text/html,"+url.PathEscape(html), "", 480, 320)
if err != nil {
log.Fatal(err)
}
defer ui.Close()
ui.Bind("checkURL", func(url string) {
ui.Eval(`document.getElementById('status').innerText = 'checking...';`)
log.Println(url)
res, err := http.Get(url)
if err != nil {
log.Println(err)
//ui.Close()
ui.Eval(`document.getElementById('status').innerText = 'error!';`)
<-ui.Done()
}
//log.Println(res.StatusCode)
if res.StatusCode == http.StatusOK {
ui.Eval(`document.getElementById('status').innerText = 'Online';`)
} else {
ui.Eval(`document.getElementById('status').innerText = 'Offline';`)
}
})
<-ui.Done()
}
/*
ui.Bind("checkURL", checkURL(url string))
func checkURL(url string) {
res, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
if res.StatusCode != http.StatusOK {
ui.Eval(`document.QuerySelector('#status').innerText = 'Online';`)
} else {
ui.Eval(`document.QuerySelector('#status').innerText = 'Offline';`)
}
}
*/