這是完整的代碼,與您在 git repo 頁(yè)面上找到的代碼沒(méi)有太大區(qū)別。package mainimport ( "fmt" "github.com/go-ping" "time")var stats = [][]string{nil}func pinging(domain string, interval int, unit string, exit int) {current_time:= time.Now().Local()current_time.Format("02-01-2000")switch unit {case "ms": interval *= 1case "sec": interval *= 1000case "min": interval *= 6000}pinger, err := ping.NewPinger(domain)if err != nil { panic(err)}// interval between pingpinger.Interval=time.Millisecond*time.Duration(interval)//number of total pingspinger.Count=exitpinger.OnRecv = func(pkt *ping.Packet) { fmt.Printf("%d bytes from %s: icmp_seq=%d time=%v\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt)}pinger.OnFinish = func(stats *ping.Statistics) { fmt.Printf("\n--- %s ping statistics ---\n", stats.Addr) fmt.Printf("%d packets transmitted, %d packets received, %v%% packet loss\n", stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss) fmt.Printf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n", stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)}fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr())pinger.Run()}我需要將這些變量 pkt.Nbytes、pkt.IPAddr、pkt.Seq、pkt.Rtt 轉(zhuǎn)換并附加到一段字符串中,這些變量是來(lái)自此 repo https://github.com/sparrc/go-ping的 *net 類型.我需要這樣做,因?yàn)橹笪視?huì)將所有內(nèi)容打印到 .csv 我該怎么做?
我如何轉(zhuǎn)換并附加到 Golang 中的一段字符串,一個(gè)來(lái)自 go-ping 存儲(chǔ)庫(kù)的網(wǎng)絡(luò)類型變量?
飲歌長(zhǎng)嘯
2023-04-04 14:09:24