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

Why is the default HTTP client passed by value and not as a pointer? #187

Open
preslavrachev opened this issue Dec 31, 2023 · 0 comments
Open

Comments

@preslavrachev
Copy link

To give a bit of context as to what I am talking about, here is how the NewClient function looks like:

// NewClient returns a new mastodon API client.
func NewClient(config *Config) *Client {
	return &Client{
		Client: *http.DefaultClient,
		Config: config,
	}
}

While I could possibly understand the concerns (prevent mutability, etc), it breaks the expected semantic. http.Client is a pointer type (as it can be seen by http.DefaultHTTPClient). Even though a copy by value is perfectly OK for now, you may never know if it won't hold a mutex or something similar in the future that would turn making a copy into a bug.

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