fix zero result print

This commit is contained in:
mazhuang 2021-11-12 11:58:21 +08:00
parent fbaa312622
commit 80eadc8df2
3 changed files with 15 additions and 10 deletions

13
main.go
View File

@ -96,15 +96,11 @@ https://github.com/XIU2/CloudflareSpeedTest
func main() {
go checkUpdate() // 检查版本更新
// 开始延迟测速
fmt.Printf("# XIU2/CloudflareSpeedTest %s \n", version)
ipVersion := "IPv4"
if task.IPv6 { // IPv6 模式判断
ipVersion = "IPv6"
}
fmt.Printf("开始延迟测速模式TCP %s端口%d ,平均延迟上限:%v平均延迟下限%v)\n", ipVersion, task.TCPPort, utils.InputMaxDelay, utils.InputMinDelay)
// 开始延迟测速
pingData := task.NewPing().Run().FilterDelay()
// 开始下载测速
speedData := task.TestDownloadSpeed(pingData)
utils.ExportCsv(speedData)
speedData.Print(task.IPv6)
@ -113,11 +109,8 @@ func main() {
fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
}
if utils.Output != "" {
fmt.Printf("完整测速结果已写入 %v 文件,请使用记事本/表格软件查看。\n", utils.Output)
}
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
fmt.Printf("按下 回车键 或 Ctrl+C 退出。\n")
fmt.Println("\n按下 回车键 或 Ctrl+C 退出。")
var pause int
fmt.Scanln(&pause)
}

View File

@ -59,6 +59,14 @@ func NewPing() *Ping {
}
func (p *Ping) Run() utils.PingDelaySet {
if len(p.ips) == 0 {
return p.csv
}
ipVersion := "IPv4"
if IPv6 { // IPv6 模式判断
ipVersion = "IPv6"
}
fmt.Printf("开始延迟测速模式TCP %s端口%d ,平均延迟上限:%v平均延迟下限%v)\n", ipVersion, TCPPort, utils.InputMaxDelay, utils.InputMinDelay)
for _, ip := range p.ips {
p.wg.Add(1)
p.control <- false

View File

@ -59,6 +59,9 @@ func ExportCsv(data []CloudflareIPData) {
if Output == "" {
Output = defaultOutput
}
if len(data) == 0 {
return
}
fp, err := os.Create(Output)
if err != nil {
log.Fatalf("创建文件[%s]失败:%v", Output, err)
@ -69,6 +72,7 @@ func ExportCsv(data []CloudflareIPData) {
w.Write([]string{"IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)"})
w.WriteAll(convertToString(data))
w.Flush()
fmt.Printf("完整测速结果已写入 %v 文件,请使用记事本/表格软件查看。\n", Output)
}
func convertToString(data []CloudflareIPData) [][]string {