func AverageLatency(host string) Metrics { REQUESTS_LIMIT := 100 var errors int64 results := make([]int64, 0, REQUESTS_LIMIT) var wg sync.WaitGroup wg.Add(REQUESTS_LIMIT) for j := 0; j < REQUESTS_LIMIT; j++ { go func() { defer wg.Done() start := time.Now() if _, err := net.LookupHost(host); err != nil { fmt.Printf("%s", err.Error()) atomic.AddInt64(&errors, 1) return } append(results, time.Since(start).Nanoseconds() / int64(time.Millisecond)) } } if waitWithTimeout(&wg, time.Duration(time.Second*DURATION_SECONDS)) { fmt.Println("There was a timeout waiting for DNS requests to finish") } return CalculateStats(&results, &errors) }