diff options
| author | mo khan <mo.khan@gmail.com> | 2019-12-08 14:24:03 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-12-08 14:24:03 -0700 |
| commit | 7fce998f980022a2954fd99d3049c422881319e3 (patch) | |
| tree | 4fc34cedc27f5d319e58c778b93da8d9caf162f1 /racer.go | |
| parent | 4748519fd9cb750de0d1dd22907e4b9af6fb81c2 (diff) | |
Diffstat (limited to 'racer.go')
| -rw-r--r-- | racer.go | 22 |
1 files changed, 22 insertions, 0 deletions
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) +} |
