Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
c8d3e5f9ca |
8
main.go
8
main.go
@@ -96,6 +96,12 @@ func LimitedHttp(rps float64, burst int) *http.Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var client = http.DefaultClient
|
||||||
|
|
||||||
|
func WithClient(nclient *http.Client) {
|
||||||
|
client = nclient
|
||||||
|
}
|
||||||
|
|
||||||
func RequestCached[T any](req *http.Request, filename string) (T, error) {
|
func RequestCached[T any](req *http.Request, filename string) (T, error) {
|
||||||
var zero T
|
var zero T
|
||||||
|
|
||||||
@@ -105,7 +111,7 @@ func RequestCached[T any](req *http.Request, filename string) (T, error) {
|
|||||||
return zero, fmt.Errorf("failed to read cache: %w", err)
|
return zero, fmt.Errorf("failed to read cache: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, httpErr := http.DefaultClient.Do(req)
|
resp, httpErr := client.Do(req)
|
||||||
if httpErr != nil {
|
if httpErr != nil {
|
||||||
return zero, fmt.Errorf("HTTP request failed: %w", httpErr)
|
return zero, fmt.Errorf("HTTP request failed: %w", httpErr)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user