Skip to content

Commit

Permalink
Display improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbbastien committed Sep 22, 2020
1 parent 550aa0d commit 9bd385c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.15
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/stretchr/testify v1.6.1 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
8 changes: 5 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
"strings"
"sync"
"time"

"github.com/logrusorgru/aurora"
)

var dlSizes = [...]int{350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000}
var ulSizes = [...]int{100, 300, 500, 800, 1000, 1500, 2500, 3000, 3500, 4000} //kB

func downloadTest(sURL string, latency time.Duration) float64 {
dlURL := strings.Split(sURL, "/upload")[0]
fmt.Printf("Download Test: ")
fmt.Printf("%-14s: ", "Download Test")
wg := new(sync.WaitGroup)

// Warming up
Expand Down Expand Up @@ -66,7 +68,7 @@ func downloadTest(sURL string, latency time.Duration) float64 {
}

func uploadTest(sURL string, latency time.Duration) float64 {
fmt.Printf("Upload Test: ")
fmt.Printf("%-14s: ", "Upload Test")
wg := new(sync.WaitGroup)

// Warm up
Expand Down Expand Up @@ -184,6 +186,6 @@ func pingTest(sURL string) time.Duration {
}
}

fmt.Println("Latency:", (l / 2.0))
fmt.Printf("\n%-14s: %v\n", "Latency", aurora.Gray(24, (l/2.0).Truncate(time.Microsecond)))
return l / 2.0
}
10 changes: 5 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"math"
"sort"
"strconv"

"github.com/logrusorgru/aurora"
)

// Server information
Expand Down Expand Up @@ -142,9 +144,7 @@ func (l ServerList) Show() {

// Show : show server information
func (s Server) Show() {
fmt.Printf(" \n")
fmt.Printf("Target Server: [%4s] %8.2fkm ", s.ID, s.Distance)
fmt.Printf(s.Name + " (" + s.Country + ") by " + s.Sponsor + "\n")
fmt.Printf("%-6s : %s %.2fkm (%s/%s) by %s\n", "Target", aurora.Magenta(s.ID), s.Distance, aurora.Magenta(s.Name), s.Country, aurora.Gray(12, s.Sponsor))
}

// StartTest : start testing to the servers.
Expand All @@ -163,8 +163,8 @@ func (svrs Servers) StartTest() {
func (svrs Servers) ShowResult() {
fmt.Printf(" \n")
if len(svrs) == 1 {
fmt.Printf("Download: %5.2f Mbit/s\n", svrs[0].DLSpeed)
fmt.Printf("Upload: %5.2f Mbit/s\n", svrs[0].ULSpeed)
fmt.Printf("%-13s : %s\n", "Download", aurora.Gray(24, fmt.Sprintf("%5.2f Mbit/s", svrs[0].DLSpeed)))
fmt.Printf("%-13s : %s\n", "Upload", aurora.Gray(24, fmt.Sprintf("%5.2f Mbit/s", svrs[0].ULSpeed)))
} else {
for _, s := range svrs {
fmt.Printf("[%4s] Download: %5.2f Mbit/s, Upload: %5.2f Mbit/s\n", s.ID, s.DLSpeed, s.ULSpeed)
Expand Down
4 changes: 2 additions & 2 deletions speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func setSourceAddr(iface string) (ip net.IP) {
}

var (
app = kingpin.New("speedtest", "Run a speedtest").Author("Newlode")
app = kingpin.New("speedtest-fpngfw", "Run a speedtest from a Forcepoint NGFW. Writen by Newlode www.newlode.io").Author("Sébastien Boulet @ Newlode Groupe - www.newlode.io")
insecure = app.Flag("insecure", "Disable TLS certificate verify").Short('i').Default("true").Bool()
iface = app.Flag("iface", "Force the use of IFACE for this test").Short('I').String()
showList = app.Flag("list", "Show available speedtest.net servers").Short('l').Bool()
Expand All @@ -82,7 +82,7 @@ var (
func main() {

var ip net.IP
kingpin.Version("1.0.6")
kingpin.Version("1.0.7")
kingpin.MustParse(app.Parse(os.Args[1:]))

setTimeout()
Expand Down
4 changes: 3 additions & 1 deletion user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/xml"
"fmt"
"io/ioutil"

"github.com/logrusorgru/aurora"
)

// User information
Expand Down Expand Up @@ -51,6 +53,6 @@ func fetchUserInfo() User {
// Show user location
func (u *User) Show(ip string) {
if u.IP != "" {
fmt.Println("Testing From IP " + ip + "/" + u.IP + " (" + u.Isp + ") [" + u.Lat + ", " + u.Lon + "]")
fmt.Printf("%-6s : %s/%s (%s) [%s,%s]\n", "Source", aurora.Gray(18, ip), aurora.Gray(24, u.IP), aurora.Cyan(u.Isp), aurora.Gray(12, u.Lat), aurora.Gray(12, u.Lon))
}
}

0 comments on commit 9bd385c

Please sign in to comment.