Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.Client.Timeout gets always overriden by the defaultTimeout when using ovh.Client #69

Open
mlcdf opened this issue Apr 21, 2023 · 0 comments

Comments

@mlcdf
Copy link
Member

mlcdf commented Apr 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant