-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from proxymo-network/custom-client-support
Add speedtest struct which contains the global variables used
- Loading branch information
Showing
8 changed files
with
121 additions
and
30 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
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
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
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
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,33 @@ | ||
package speedtest | ||
|
||
import "net/http" | ||
|
||
// Speedtest is a speedtest client. | ||
type Speedtest struct { | ||
doer *http.Client | ||
} | ||
|
||
// Option is a function that can be passed to New to modify the Client. | ||
type Option func(*Speedtest) | ||
|
||
// WithDoer sets the http.Client used to make requests. | ||
func WithDoer(doer *http.Client) Option { | ||
return func(s *Speedtest) { | ||
s.doer = doer | ||
} | ||
} | ||
|
||
// New creates a new speedtest client. | ||
func New(opts ...Option) *Speedtest { | ||
s := &Speedtest{ | ||
doer: http.DefaultClient, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(s) | ||
} | ||
|
||
return s | ||
} | ||
|
||
var defaultClient = New() |
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,26 @@ | ||
package speedtest | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
t.Run("DefaultDoer", func(t *testing.T) { | ||
c := New() | ||
|
||
if c.doer == nil { | ||
t.Error("doer is nil by") | ||
} | ||
}) | ||
|
||
t.Run("CustomDoer", func(t *testing.T) { | ||
doer := &http.Client{} | ||
|
||
c := New(WithDoer(doer)) | ||
if c.doer != doer { | ||
t.Error("doer is not the same") | ||
} | ||
}) | ||
|
||
} |
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
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