Skip to content

Commit

Permalink
added option to test via tcp or http
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed Sep 13, 2016
1 parent 43cbcd3 commit c9d1ba4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (

var (
repeats = flag.Int("repeats", 1, "Number of repeats")
useHTTP = flag.Bool("http", false, "Use http transport (default is tcp)")
)

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
Expand Down Expand Up @@ -99,7 +100,7 @@ func (rs AWSRegions) Swap(i, j int) {
}

// CalcLatency returns list of aws regions sorted by Latency
func CalcLatency(repeats int) *AWSRegions {
func CalcLatency(repeats int, useHTTP bool) *AWSRegions {
regions := AWSRegions{
{Name: "US-East (Virginia)", Code: "us-east-1"},
{Name: "US-West (California)", Code: "us-west-1"},
Expand All @@ -121,7 +122,12 @@ func CalcLatency(repeats int) *AWSRegions {
wg.Add(len(regions))

for i := range regions {
go regions[i].CheckLatencyTCP(&wg)
if useHTTP {
go regions[i].CheckLatencyHTTP(&wg)
} else {
go regions[i].CheckLatencyTCP(&wg)
}

}

wg.Wait()
Expand All @@ -135,7 +141,7 @@ func main() {

flag.Parse()

regions := *CalcLatency(*repeats)
regions := *CalcLatency(*repeats, *useHTTP)

outFmt := "%5v %-30s %20s\n"
fmt.Printf(outFmt, "", "Region", "Latency")
Expand Down

0 comments on commit c9d1ba4

Please sign in to comment.