Repository: moby/moby (language: go)

Issue:
client: disable deprecated NewClient() and NewEnvClient()
The `NewClient()` and `NewEnvClient()` functions were deprecated in 18.03 in
commit 772edd020cc784913973387b00c4d0c526a10a26 (https://github.com/moby/moby/pull/36140), but they continued to be functional.

Searching public repositories on GitHub shows that there's quite some projects
that haven't updated their code to use the replacements.

This patch updates both functions to become non-functional (to enforce a compilation
failure), but extend the function's documentaiton with instructions on migrating to
their non-deprecated alternatives. This should hopefully assist projects to migrate
their code.

**- Description for the changelog**
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->


**- A picture of a cute animal (not mandatory but encouraged)**




Discussion / hints:
@AkihiroSuda updated with what I described above; let me know if you think this is a better approach.
@AkihiroSuda @corhere @cpuguy83 PTAL (happy to get feedback on the approach; mostly wanting to make the replacement discoverable)
In addition to @corhere's comments, I think creating runtime errors for this is not ideal and it would be better to error out at compile time.

Fix patch:
diff --git a/client/client.go b/client/client.go
index 224ed6f454d28..8d32976b2b6e9 100644
--- a/client/client.go
+++ b/client/client.go
@@ -6,9 +6,10 @@ https://docs.docker.com/engine/api/
 
 # Usage
 
-You use the library by creating a client object and calling methods on it. The
-client can be created either from environment variables with NewClientWithOpts(client.FromEnv),
-or configured manually with NewClient().
+You use the library by constructing a client object using [NewClientWithOpts]
+and calling methods on it. The client can be configured from environment
+variables by passing the [FromEnv] option, or configured manually by passing any
+of the other available [Opts].
 
 For example, to list running containers (the equivalent of "docker ps"):
 
diff --git a/client/client_deprecated.go b/client/client_deprecated.go
index 54cdfc29a84b6..9e366ce20d160 100644
--- a/client/client_deprecated.go
+++ b/client/client_deprecated.go
@@ -9,7 +9,11 @@ import "net/http"
 // It won't send any version information if the version number is empty. It is
 // highly recommended that you set a version or your client may break if the
 // server is upgraded.
-// Deprecated: use NewClientWithOpts
+//
+// Deprecated: use [NewClientWithOpts] passing the [WithHost], [WithVersion],
+// [WithHTTPClient] and [WithHTTPHeaders] options. We recommend enabling API
+// version negotiation by passing the [WithAPIVersionNegotiation] option instead
+// of WithVersion.
 func NewClient(host string, version string, client *http.Client, httpHeaders map[string]string) (*Client, error) {
 	return NewClientWithOpts(WithHost(host), WithVersion(version), WithHTTPClient(client), WithHTTPHeaders(httpHeaders))
 }
@@ -17,7 +21,7 @@ func NewClient(host string, version string, client *http.Client, httpHeaders map
 // NewEnvClient initializes a new API client based on environment variables.
 // See FromEnv for a list of support environment variables.
 //
-// Deprecated: use NewClientWithOpts(FromEnv)
+// Deprecated: use [NewClientWithOpts] passing the [FromEnv] option.
 func NewEnvClient() (*Client, error) {
 	return NewClientWithOpts(FromEnv)
 }


Test patch: