package cmd import ( "fmt" "github.com/showwin/speedtest-go/speedtest" "github.com/spf13/cobra" ) var netCmd = &cobra.Command{ Use: "net", Short: "Network test using SpeedTest.net.", Long: "A network test that utilizes the SpeedTest.net API to determine network bandwidth and latency.", Run: func(cmd *cobra.Command, args []string) { user, _ := speedtest.FetchUserInfo() serverList, _ := speedtest.FetchServers(user) targets, _ := serverList.FindServer([]int{}) for _, s := range targets { s.PingTest() s.DownloadTest(false) s.UploadTest(false) fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed) } }, } func init() { // add ping command to the main program rootCmd.AddCommand(netCmd) }