-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV 1793: Track latency, status codes, and errors from CLI games (#113)
* track latency and status code from CLI games * actually track errors from snake responses
- Loading branch information
Showing
3 changed files
with
307 additions
and
38 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,28 @@ | ||
package commands | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type TimedHttpClient interface { | ||
Get(url string) (*http.Response, time.Duration, error) | ||
Post(url string, contentType string, body io.Reader) (*http.Response, time.Duration, error) | ||
} | ||
|
||
type timedHTTPClient struct { | ||
*http.Client | ||
} | ||
|
||
func (client timedHTTPClient) Get(url string) (*http.Response, time.Duration, error) { | ||
startTime := time.Now() | ||
res, err := client.Client.Get(url) | ||
return res, time.Since(startTime), err | ||
} | ||
|
||
func (client timedHTTPClient) Post(url string, contentType string, body io.Reader) (*http.Response, time.Duration, error) { | ||
startTime := time.Now() | ||
res, err := client.Client.Post(url, contentType, body) | ||
return res, time.Since(startTime), err | ||
} |
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
Oops, something went wrong.