Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(11-select): 🎉 11-select initial framework without goroutines
- Loading branch information
1 parent
9fead70
commit b0a2641
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module racer | ||
|
||
go 1.17 | ||
|
||
require github.com/matryer/is v1.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= | ||
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package racer | ||
|
||
import ( | ||
http "net/http" | ||
"time" | ||
) | ||
|
||
// Racer returns the fastest responding website. | ||
func Racer(a, b string) (winner string) { | ||
startA := time.Now() | ||
http.Get(a) | ||
aDuration := time.Since(startA) | ||
|
||
startB := time.Now() | ||
http.Get(b) | ||
bDuration := time.Since(startB) | ||
|
||
if aDuration < bDuration { | ||
return a | ||
} | ||
return b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package racer_test | ||
|
||
import ( | ||
src "racer" | ||
"testing" | ||
|
||
iz "github.com/matryer/is" | ||
) | ||
|
||
func TestRacer(t *testing.T) { | ||
is := iz.New(t) | ||
|
||
slowURL := "https://www.facebook.com" | ||
fastURL := "https://www.quii.co.uk" | ||
|
||
want := fastURL | ||
got := src.Racer(slowURL, fastURL) | ||
|
||
is.Equal(got, want) // the fast URL should be quii obviously | ||
} |