-
Notifications
You must be signed in to change notification settings - Fork 130
/
main.go
62 lines (51 loc) · 1.34 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
package main
import (
"encoding/json"
"fmt"
"github.com/fatih/color"
"log"
"net/http"
"time"
)
type IpInfo struct {
Ip string `json:"ip"`
City string `json:"city"`
Region string `json:"region"`
Country string `json:"country"`
Org string `json:"org"`
}
func main() {
var (
s [12]string
c = make(chan Result)
t = time.After(time.Second * 10)
)
go func() {
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fzhanghanyun%2Fbacktrace&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false")
}()
yellow := color.New(color.FgHiYellow).Add(color.Bold).SprintFunc()
green := color.New(color.FgHiGreen).SprintFunc()
cyan := color.New(color.FgHiCyan).SprintFunc()
log.Println("正在测试三网回程路由...")
rsp, _ := http.Get("http://ipinfo.io")
info := IpInfo{}
json.NewDecoder(rsp.Body).Decode(&info)
fmt.Println(green("国家: ") + cyan(info.Country) + green(" 城市: ") + cyan(info.City) + green(" 服务商: ") + cyan(info.Org))
fmt.Println(green("项目地址:"), yellow("https://github.com/zhanghanyun/backtrace"))
for i := range ips {
go trace(c, i)
}
loop:
for range s {
select {
case o := <-c:
s[o.i] = o.s
case <-t:
break loop
}
}
for _, r := range s {
fmt.Println(r)
}
log.Println(green("测试完成!"))
}