Initial commit
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
package domainser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"stat/models/domainmod"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FnCheckFinish func(result *domainmod.CheckResult)
|
||||
|
||||
type Checker interface {
|
||||
Check() error
|
||||
}
|
||||
|
||||
type ApiPath struct {
|
||||
Create string
|
||||
Query string
|
||||
Sleep time.Duration
|
||||
NeedCreate bool
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
Id int `json:"id"`
|
||||
NodeName string `json:"node_name"`
|
||||
IspName string `json:"isp_name"`
|
||||
IspCode int `json:"isp_code"`
|
||||
Rand int
|
||||
}
|
||||
|
||||
type NodeList []Node
|
||||
|
||||
func (n NodeList) Len() int { return len(n) }
|
||||
func (n NodeList) Less(i, j int) bool {
|
||||
return n[i].Rand < n[j].Rand
|
||||
}
|
||||
func (n NodeList) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
|
||||
|
||||
func (n NodeList) SIdList(max int32) string {
|
||||
if max < 1 {
|
||||
max = 1
|
||||
}
|
||||
for _, node := range n {
|
||||
node.Rand = rand.Int()
|
||||
}
|
||||
sort.Sort(n)
|
||||
ss := make([]string, 0)
|
||||
for _, node := range n {
|
||||
if strings.Contains(node.IspName, "电信") || strings.Contains(node.IspName, "移动") || strings.Contains(node.IspName, "联通") {
|
||||
ss = append(ss, fmt.Sprintf("%d", node.Id))
|
||||
}
|
||||
}
|
||||
if len(ss) > int(max) {
|
||||
ss = ss[:max]
|
||||
}
|
||||
return strings.Join(ss, ",")
|
||||
}
|
||||
|
||||
type CommonResp struct {
|
||||
ErrorCode int `json:"error_code"`
|
||||
Error string `json:"error"`
|
||||
Data struct {
|
||||
Id *string `json:"id"`
|
||||
List *NodeList `json:"list"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type DomainResp struct {
|
||||
ErrorCode int `json:"error_code"`
|
||||
Error string `json:"error"`
|
||||
Data map[string]int `json:"data"`
|
||||
}
|
||||
|
||||
type WebTestNode struct {
|
||||
NodeId int `json:"node_id"`
|
||||
NodeName string `json:"node_name"`
|
||||
Host string `json:"host"`
|
||||
OriginIp string `json:"origin_ip"`
|
||||
HttpCode int `json:"http_code"`
|
||||
RemoteIp string `json:"remote_ip"`
|
||||
SizeDownload int `json:"size_download"`
|
||||
SpeedDownload int `json:"speed_download"`
|
||||
TimeConnect float64 `json:"time_connect"`
|
||||
TimeNamelookup float64 `json:"time_namelookup"`
|
||||
TimeStarttransfer float64 `json:"time_starttransfer"`
|
||||
TimeTotal float64 `json:"time_total"`
|
||||
ReportSource string `json:"report_source"`
|
||||
SessionId string `json:"session_id"`
|
||||
IpRegion string `json:"ip_region"`
|
||||
IpIsp string `json:"ip_isp"`
|
||||
ErrorCode int `json:"error_code"`
|
||||
Error string `json:"error"`
|
||||
TimeId string `json:"time_id"`
|
||||
}
|
||||
type WebTestNodeList []*WebTestNode
|
||||
|
||||
func (n *WebTestNode) ErrorString() string {
|
||||
return fmt.Sprintf("节点【%s】检测失败", n.NodeName)
|
||||
}
|
||||
|
||||
type WebResp struct {
|
||||
Id string `json:"id"`
|
||||
MaxNode int `json:"max_node"`
|
||||
Done bool `json:"done"`
|
||||
List WebTestNodeList `json:"list"`
|
||||
}
|
||||
|
||||
type HijackTestNode struct {
|
||||
NodeId int `json:"node_id"`
|
||||
Hijack bool `json:"hijack"`
|
||||
NodeName string `json:"node_name"`
|
||||
RemoteIp string `json:"remote_ip"`
|
||||
Url string `json:"url"`
|
||||
ReportSource string `json:"report_source"`
|
||||
}
|
||||
|
||||
func (n *HijackTestNode) ErrorString() string {
|
||||
return fmt.Sprintf("节点【%s】已劫持", n.NodeName)
|
||||
}
|
||||
|
||||
type HijackResp struct {
|
||||
Done bool `json:"done"`
|
||||
HijackNum int `json:"hijack_num"`
|
||||
Id string `json:"id"`
|
||||
List []*HijackTestNode `json:"list"`
|
||||
MaxNode int `json:"max_node"`
|
||||
}
|
||||
|
||||
type PolluteResp struct {
|
||||
ErrorCode int `json:"error_code"`
|
||||
Error string `json:"error"`
|
||||
Data map[string]int `json:"data"`
|
||||
}
|
||||
Reference in New Issue
Block a user