update: 修复没有结果时Hop返回0的问题

This commit is contained in:
sjlleo
2022-05-13 15:29:29 +08:00
parent c63fee7d06
commit 97557159e7

View File

@@ -50,7 +50,10 @@ func New() table.Table {
func tableDataGenerator(v2 methods.TracerouteHop) *rowData {
if v2.Address == nil {
return &rowData{}
return &rowData{
Hop: int64(v2.TTL),
IP: "*",
}
} else {
// 初始化变量
var iPGeoData *ipgeo.IPGeoData
@@ -72,25 +75,29 @@ func tableDataGenerator(v2 methods.TracerouteHop) *rowData {
iPGeoData, err = ipgeo.LeoIP(ipStr)
}
ptr, err_LookupAddr := net.LookupAddr(ipStr)
lantency = fmt.Sprintf("%.2fms", v2.RTT.Seconds()*1000)
if err_LookupAddr != nil {
IP = fmt.Sprint(ipStr)
} else {
IP = fmt.Sprint(ptr[0], " (", ipStr, ") ")
}
if iPGeoData.Owner == "" {
iPGeoData.Owner = iPGeoData.Isp
}
if err != nil {
fmt.Print("Error: ", err)
return &rowData{}
return &rowData{
Hop: int64(v2.TTL),
IP: IP,
Latency: lantency,
}
} else {
ptr, err := net.LookupAddr(ipStr)
lantency = fmt.Sprintf("%.2fms", v2.RTT.Seconds()*1000)
if err != nil {
IP = fmt.Sprint(ipStr)
} else {
IP = fmt.Sprint(ptr[0], " (", ipStr, ") ")
}
if iPGeoData.Owner == "" {
iPGeoData.Owner = iPGeoData.Isp
}
return &rowData{
Hop: int64(v2.TTL),
IP: IP,