Skip to content

Commit

Permalink
fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Larvan2 committed Nov 14, 2023
1 parent b35f165 commit 399560e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/geo/cmd_look.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,22 @@ func look(cmd *cobra.Command, args []string) error {
if noResolve {
return nil
}
ips, err := net.DefaultResolver.LookupIP(context.Background(), "ip", domainName)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

go func() {
<-ctx.Done()
fmt.Print("\n\n🌎Resolved ", domainName, " timeout")
}()

ips, err := net.DefaultResolver.LookupIP(ctx, "ip", domainName)
if err != nil {
fmt.Println("\n\n❌Fail to resolve", domainName, ", skipped.")
}
ip = ips[0]
if len(ips) != 0 {
ip = ips[0]
}

fmt.Print("\n\n🌎Resolved ", domainName, " as ", ip, "\n\n")
}

Expand Down

0 comments on commit 399560e

Please sign in to comment.