-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (38 loc) · 828 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 (
"flag"
"fmt"
"html"
"log"
"net/http"
)
const FileName = "config.json"
var debug *bool
func main() {
debug = flag.Bool("debug", false, "output debug msg")
web := flag.String("web", ":1234", "web log listening ip:port")
config, err := ReadConfig(FileName)
flag.Parse()
if err != nil {
log.Fatal(err)
}
p := NewProbe(config)
go p.Start()
go ListenAndServe(config.Listen, p.GetFastestServer)
if *web == "" {
return
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<html><body>")
for _, v := range p.Servers {
fmt.Fprintf(w, "%s<br>", html.EscapeString(v.String()))
}
fmt.Fprintf(w, "now use:%s", p.GetFastestServer())
})
log.Fatal(http.ListenAndServe(*web, nil))
}
func debugOut(d ...interface{}) {
if *debug {
log.Println(d)
}
}