http.Client.Timeout gets always overriden by the defaultTimeout when using ovh.Client
mlcdf opened this issue · 0 comments
mlcdf commented
Hello,
I have a problem with the Timeout field on the ovh.Client
struct. While it may be convenient for simple use case, it introduces an unexpected behaviour: it always overrides the http.Client.Timeout
, with a default values of 3 minutes (when using the ovh.Client "constructor").
For example, with the following code, despite creating a client with a 30s timeout, the actual timeout will be of 3 minutes.
httpClient := http.Client{Timeout: 30*time.Second}
client, _ := ovh.NewClient(
"ovh-eu",
YOUR_APPLICATION_KEY,
YOUR_APPLICATION_SECRET,
YOUR_CONSUMER_KEY,
)
client.Client = http.Client
Now let's say, I want to wrap ovh.Client
.
type MyClient struct {
ovh.Client
// other fields
}
// Here I only want to expose httpClient because this is a great abstraction and one that is
// conventionally use to allows users of a library to customize everything regarding the HTTP stuff.
func NewClient(httpClient http.Client) *MyClient {
client := ovh.NewClient(...)
client.Client = httpClient
// This is weird
if httpClient.Timeout {
client.Timeout = httpClient.Timeout
}
// other stuff
// ...
return client
}
I feel like ovh.Client.Timeout
creates more problems that it solves. So in case of a potential v2 (because removing the field would be a breaking chance), I think this field should be removed.