From 7fce998f980022a2954fd99d3049c422881319e3 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sun, 8 Dec 2019 14:24:03 -0700 Subject: start work on racer --- racer.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 racer.go (limited to 'racer.go') diff --git a/racer.go b/racer.go new file mode 100644 index 0000000..b954222 --- /dev/null +++ b/racer.go @@ -0,0 +1,22 @@ +package main + +import ( + "net/http" + "time" +) + +func Racer(a, b string) (winner string) { + aDuration := measureResponseTime(a) + bDuration := measureResponseTime(b) + + if aDuration < bDuration { + return a + } + return b +} + +func measureResponseTime(url string) time.Duration { + start := time.Now() + http.Get(url) + return time.Since(start) +} -- cgit v1.2.3