kiwix, weather: name the client timeout constant (V-581)
Both clients used a bare 10*time.Second literal for the http.Client timeout, unlike websearch.DefaultTimeout which carries a comment explaining the number. Naming them puts the reason (LAN ZIM read vs. a public API over the internet) next to the value; the constants equal what was there before, so behaviour is unchanged.
This commit is contained in:
@@ -39,11 +39,16 @@ type Client struct {
|
||||
http *http.Client
|
||||
}
|
||||
|
||||
// clientTimeout — the whole request, search or article. The server is on the
|
||||
// same box (see the package doc), so this is slack for a cold ZIM read, not a
|
||||
// budget tuned against a flaky link the way websearch.DefaultTimeout is.
|
||||
const clientTimeout = 10 * time.Second
|
||||
|
||||
// New makes a client for a Kiwix base URL like http://127.0.0.1:8034.
|
||||
func New(baseURL string) *Client {
|
||||
return &Client{
|
||||
base: strings.TrimRight(baseURL, "/"),
|
||||
http: &http.Client{Timeout: 10 * time.Second},
|
||||
http: &http.Client{Timeout: clientTimeout},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,13 +13,19 @@ import (
|
||||
"github.com/kami/maven/internal/morph"
|
||||
)
|
||||
|
||||
// clientTimeout — the whole request, geocode or forecast. Both are one call to
|
||||
// a public API over the internet rather than a LAN service, hence longer than
|
||||
// a bare "it's slow" budget; there is no retry behind it, so a slow reply
|
||||
// still costs the caller the whole wait.
|
||||
const clientTimeout = 10 * time.Second
|
||||
|
||||
type OpenMeteoProvider struct {
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
func NewOpenMeteoProvider() *OpenMeteoProvider {
|
||||
return &OpenMeteoProvider{
|
||||
httpClient: &http.Client{Timeout: 10 * time.Second},
|
||||
httpClient: &http.Client{Timeout: clientTimeout},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user