-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
47 lines (39 loc) · 917 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"flag"
"fmt"
"os"
"github.com/mtojek/aws-closest-region/closest"
log "github.com/sirupsen/logrus"
)
func main() {
var verbose bool
flag.BoolVar(&verbose, "verbose", false, "verbose mode")
flag.Usage = usage
flag.Parse()
log.SetFormatter(&log.TextFormatter{
DisableLevelTruncation: true,
DisableTimestamp: true,
})
if verbose {
log.SetLevel(log.InfoLevel)
} else {
log.SetLevel(log.ErrorLevel)
}
serviceName := flag.Arg(0)
services := new(closest.Services)
serviceEndpoints, err := services.EndpointsForService(serviceName)
if err != nil {
log.Fatal(err)
}
regions := new(closest.Regions)
closestEndpoint, err := regions.FindClosest(serviceEndpoints)
if err != nil {
log.Fatal(err)
}
fmt.Println(closestEndpoint)
}
func usage() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s <flags> [serviceName]:\n", os.Args[0])
flag.PrintDefaults()
}