in main.go [44:100]
func main() {
flag.BoolVar(&top, "top", false, "")
flag.IntVar(&number, "n", 10, "")
flag.IntVar(&concurrency, "c", 10, "")
flag.DurationVar(&timeout, "t", time.Duration(0), "")
flag.BoolVar(&verbose, "v", false, "")
flag.BoolVar(&csv, "csv", false, "")
flag.BoolVar(&csvCum, "csv-cum", false, "")
flag.StringVar(®ion, "r", "", "")
flag.StringVar(&endpointsURL, "url", "https://global.gcping.com/api/endpoints", "")
flag.Usage = usage
flag.Parse()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Fetch and cache endpoint map in memory for the duration of the
// process.
endpoints, err := config.EndpointsFromServer(ctx, endpointsURL)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if number < 0 || concurrency <= 0 {
usage()
}
if csv {
verbose = false // if output is CSV, no need for verbose output
}
if region != "" {
if _, found := endpoints[region]; !found {
fmt.Printf("region %q is not supported or does not exist\n", region)
os.Exit(1)
}
}
client = &http.Client{
Timeout: timeout,
}
w := &worker{}
go w.start()
switch {
case region != "":
w.reportRegion(endpoints, region)
case top:
w.reportTop(endpoints)
case csvCum:
w.reportCSV(endpoints)
default:
w.reportAll(endpoints)
}
}