Commit d9b1af3
Changed files (4)
cmd/misc/speedtest.go
@@ -0,0 +1,48 @@
+package misc
+
+import (
+ "fmt"
+
+ "github.com/showwin/speedtest-go/speedtest"
+ "github.com/spf13/cobra"
+)
+
+var SpeedTestCmd = &cobra.Command{
+ Use: "speedtest",
+ Short: "Speedtest",
+ Run: func(cmd *cobra.Command, args []string) {
+ // https://github.com/showwin/speedtest-go#api-usage
+
+ var speedtestClient = speedtest.New()
+
+ serverList, _ := speedtestClient.FetchServers()
+ targets, _ := serverList.FindServer([]int{})
+
+ for _, s := range targets {
+ fmt.Printf("Server: %s\n", s.Name)
+
+ err := s.PingTest(nil)
+ if err != nil {
+ return
+ }
+
+ err = s.DownloadTest()
+ if err != nil {
+ return
+ }
+
+ err = s.UploadTest()
+ if err != nil {
+ return
+ }
+
+ fmt.Printf("" +
+ fmt.Sprintf("Latency: %s\n", s.Latency) +
+ fmt.Sprintf("Download: %s\n", s.DLSpeed) +
+ fmt.Sprintf("Upload: %s\n", s.ULSpeed),
+ )
+
+ s.Context.Reset()
+ }
+ },
+}
cmd/root.go
@@ -27,6 +27,7 @@ func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(get.Cmd)
rootCmd.AddCommand(generate.Cmd)
+ rootCmd.AddCommand(misc.SpeedTestCmd)
rootCmd.AddCommand(misc.ShouldIDeployTodayCmd)
rootCmd.AddCommand(misc.TimerCmd)
rootCmd.AddCommand(misc.StopwatchCmd)
go.mod
@@ -11,6 +11,7 @@ require (
github.com/sethvargo/go-diceware v0.3.0
github.com/sethvargo/go-password v0.2.0
github.com/shirou/gopsutil v3.21.11+incompatible
+ github.com/showwin/speedtest-go v1.7.8
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/cobra v1.8.0
golang.design/x/clipboard v0.7.0
go.sum
@@ -55,6 +55,8 @@ github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc
github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
+github.com/showwin/speedtest-go v1.7.8 h1:UZbFQ/ArVgPvkR03egSeTM2FXBd6qJsLp8lzt9aeod0=
+github.com/showwin/speedtest-go v1.7.8/go.mod h1:uLgdWCNarXxlYsL2E5TOZpCIwpgSWnEANZp7gfHXHu0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=