refactored out http fetching code into Fetcher{}/fetch.go

This commit is contained in:
T.v.Dein
2024-01-16 19:27:46 +01:00
committed by GitHub
parent 78e5de61d2
commit 3fd75fa53d
4 changed files with 104 additions and 77 deletions

View File

@@ -27,6 +27,9 @@ import (
"time"
)
// I add an artificial "ID" to each HTTP request and the corresponding
// respose for debugging purposes so that the pair of them can be
// easier associated in debug output
var letters = []rune("ABCDEF0123456789")
func getid() string {
@@ -37,8 +40,10 @@ func getid() string {
return string(b)
}
// retry after HTTP 50x errors or err!=nil
const RetryCount = 3
// used to inject debug log and implement retries
type loggingTransport struct{}
// escalating timeout, $retry^2 seconds
@@ -75,7 +80,7 @@ func drainBody(resp *http.Response) {
}
}
// our logging transport with retries
// the actual logging transport with retries
func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error) {
// just requred for debugging
id := getid()