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:
Rob O'Dwyer 2022-10-04 15:53:29 -07:00 committed by GitHub
parent 3094a3041f
commit 5f60ccbba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 307 additions and 38 deletions

28
cli/commands/http.go Normal file
View 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
}