Skip to content

Commit

Permalink
Merge pull request #3 from italolelis/errgroup-context
Browse files Browse the repository at this point in the history
Changed to context errgroup
  • Loading branch information
italolelis committed Oct 19, 2018
2 parents b6430e4 + cfe255d commit 4de2c77
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ func NewCheckCmd(ctx context.Context, timeout time.Duration) *cobra.Command {
Short: "Checks if a domain is reachable",
Aliases: []string{"v"},
Run: func(cmd *cobra.Command, args []string) {
var wg errgroup.Group
var results [][]interface{}
// wg, ctx := errgroup.WithContext(ctx)
wg, ctx := errgroup.WithContext(ctx)
logger := log.WithContext(ctx)

for _, domain := range args {
Expand Down Expand Up @@ -56,11 +55,23 @@ func NewCheckCmd(ctx context.Context, timeout time.Duration) *cobra.Command {
})
}

wg.Wait()
if err := wg.Wait(); err != nil {
logger.WithError(err).Error("An error happened when trying to reach an URI")
return
}

if logger.Level == alog.DebugLevel {
table := termtables.CreateTable()
table.AddHeaders("Domain", "Status Code", "DNS Lookup", "TCP Connection", "TLS Handshake", "Server Processing", "Content Transfer", "Total Time")
table.AddHeaders(
"Domain",
"Status Code",
"DNS Lookup",
"TCP Connection",
"TLS Handshake",
"Server Processing",
"Content Transfer",
"Total Time",
)

for _, r := range results {
table.AddRow(r...)
Expand Down

0 comments on commit 4de2c77

Please sign in to comment.