Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -us flag to only ping US regions #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/awsping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
verbose = flag.Int("verbose", 0, "Verbosity level (0: name-latency); 1: code-name-latency; 2: code-name-tries-avg")
service = flag.String("service", "dynamodb", "AWS Service: ec2, sdb, sns, sqs, ...")
listRegions = flag.Bool("list-regions", false, "Show list of regions")
usOnly = flag.Bool("us", false, "Only US regions")
)

func main() {
Expand All @@ -29,6 +30,9 @@ func main() {
}

regions := awsping.GetRegions()
if *usOnly {
regions = awsping.GetRegionsUS()
}

if *listRegions {
lo := awsping.NewOutput(awsping.ShowOnlyRegions, 0)
Expand Down
22 changes: 17 additions & 5 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,24 @@ func (lo *LatencyOutput) Show(regions *AWSRegions) {
}
}

// GetRegions returns a list of regions
// GetRegions returns a list of all regions
func GetRegions() AWSRegions {
us := GetRegionsUS()
other := GetNonUSRegions()

return append(us, other...)
}

func GetRegionsUS() AWSRegions {
return AWSRegions{
NewRegion("US East (N. Virginia)", "us-east-1"),
NewRegion("US East (Ohio)", "us-east-2"),
NewRegion("US West (N. California)", "us-west-1"),
NewRegion("US West (Oregon)", "us-west-2"),
}
}

func GetNonUSRegions() AWSRegions {
return AWSRegions{
NewRegion("Africa (Cape Town)", "af-south-1"),
NewRegion("Asia Pacific (Hong Kong)", "ap-east-1"),
Expand All @@ -142,10 +158,6 @@ func GetRegions() AWSRegions {
NewRegion("Middle East (UAE)", "me-central-1"),
NewRegion("Middle East (Bahrain)", "me-south-1"),
NewRegion("South America (Sao Paulo)", "sa-east-1"),
NewRegion("US East (N. Virginia)", "us-east-1"),
NewRegion("US East (Ohio)", "us-east-2"),
NewRegion("US West (N. California)", "us-west-1"),
NewRegion("US West (Oregon)", "us-west-2"),
NewRegion("Israel (Tel Aviv)", "il-central-1"),
}
}
Expand Down
Loading