mattn / go-mastodon

mastodon client for golang
MIT License
599 stars 85 forks source link

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

Open preslavrachev opened 7 months ago

preslavrachev commented 7 months ago

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.