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
This commit is contained in:
parent
3094a3041f
commit
5f60ccbba8
3 changed files with 307 additions and 38 deletions
28
cli/commands/http.go
Normal file
28
cli/commands/http.go
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue