Browse code

client: touch-up some godoc

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/10/07 01:38:38
Showing 5 changed files
... ...
@@ -99,11 +99,9 @@ const DummyHost = "api.moby.localhost"
99 99
 // This version may be lower than the version of the api library module used.
100 100
 const MaxAPIVersion = "1.52"
101 101
 
102
-// fallbackAPIVersion is the version to fallback to if API-version negotiation
103
-// fails. This version is the highest version of the API before API-version
104
-// negotiation was introduced. If negotiation fails (or no API version was
105
-// included in the API response), we assume the API server uses the most
106
-// recent version before negotiation was introduced.
102
+// fallbackAPIVersion is the version to fall back to if API-version negotiation
103
+// fails. API versions below this version are not supported by the client,
104
+// and not considered when negotiating.
107 105
 const fallbackAPIVersion = "1.24"
108 106
 
109 107
 // Ensure that Client always implements APIClient.
... ...
@@ -311,8 +309,7 @@ func (cli *Client) ClientVersion() string {
311 311
 // If the API server's ping response does not contain an API version, or if the
312 312
 // client did not get a successful ping response, it assumes it is connected with
313 313
 // an old daemon that does not support API version negotiation, in which case it
314
-// downgrades to the latest version of the API before version negotiation was
315
-// added (1.24).
314
+// downgrades to the lowest supported API version.
316 315
 func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
317 316
 	if !cli.manualOverride {
318 317
 		// Avoid concurrent modification of version-related fields
... ...
@@ -337,10 +334,8 @@ func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
337 337
 // ([EnvOverrideAPIVersion]) environment variable, or if the client is initialized
338 338
 // with a fixed version ([WithVersion]), no negotiation is performed.
339 339
 //
340
-// If the API server's ping response does not contain an API version, we assume
341
-// we are connected with an old daemon without API version negotiation support,
342
-// and downgrade to the latest version of the API before version negotiation was
343
-// added (1.24).
340
+// If the API server's ping response does not contain an API version, it falls
341
+// back to the oldest API version supported.
344 342
 func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) {
345 343
 	if !cli.manualOverride {
346 344
 		// Avoid concurrent modification of version-related fields
... ...
@@ -355,8 +350,6 @@ func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) {
355 355
 // API version from the ping response.
356 356
 func (cli *Client) negotiateAPIVersionPing(pingVersion string) {
357 357
 	pingVersion = strings.TrimPrefix(pingVersion, "v")
358
-
359
-	// default to the latest version before versioning headers existed
360 358
 	if pingVersion == "" {
361 359
 		pingVersion = fallbackAPIVersion
362 360
 	}
... ...
@@ -303,9 +303,8 @@ func checkResponseErr(serverResp *http.Response) (retErr error) {
303 303
 			daemonErr = errors.New(strings.TrimSpace(errorResponse.Message))
304 304
 		}
305 305
 	} else {
306
-		// Fall back to returning the response as-is for API versions < 1.24
307
-		// that didn't support JSON error responses, and for situations
308
-		// where a plain text error is returned. This branch may also catch
306
+		// Fall back to returning the response as-is for situations where a
307
+		// plain text error is returned. This branch may also catch
309 308
 		// situations where a proxy is involved, returning a HTML response.
310 309
 		daemonErr = errors.New(strings.TrimSpace(string(body)))
311 310
 	}
... ...
@@ -74,9 +74,9 @@ func TestSetHostHeader(t *testing.T) {
74 74
 	}
75 75
 }
76 76
 
77
-// TestPlainTextError tests the server returning an error in plain text for
78
-// backwards compatibility with API versions <1.24. All other tests use
79
-// errors returned as JSON
77
+// TestPlainTextError tests the server returning an error in plain text.
78
+// API versions < 1.24 returned plain text errors, but we may encounter
79
+// other situations where a non-JSON error is returned.
80 80
 func TestPlainTextError(t *testing.T) {
81 81
 	client, err := NewClientWithOpts(WithMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")))
82 82
 	assert.NilError(t, err)
... ...
@@ -99,11 +99,9 @@ const DummyHost = "api.moby.localhost"
99 99
 // This version may be lower than the version of the api library module used.
100 100
 const MaxAPIVersion = "1.52"
101 101
 
102
-// fallbackAPIVersion is the version to fallback to if API-version negotiation
103
-// fails. This version is the highest version of the API before API-version
104
-// negotiation was introduced. If negotiation fails (or no API version was
105
-// included in the API response), we assume the API server uses the most
106
-// recent version before negotiation was introduced.
102
+// fallbackAPIVersion is the version to fall back to if API-version negotiation
103
+// fails. API versions below this version are not supported by the client,
104
+// and not considered when negotiating.
107 105
 const fallbackAPIVersion = "1.24"
108 106
 
109 107
 // Ensure that Client always implements APIClient.
... ...
@@ -311,8 +309,7 @@ func (cli *Client) ClientVersion() string {
311 311
 // If the API server's ping response does not contain an API version, or if the
312 312
 // client did not get a successful ping response, it assumes it is connected with
313 313
 // an old daemon that does not support API version negotiation, in which case it
314
-// downgrades to the latest version of the API before version negotiation was
315
-// added (1.24).
314
+// downgrades to the lowest supported API version.
316 315
 func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
317 316
 	if !cli.manualOverride {
318 317
 		// Avoid concurrent modification of version-related fields
... ...
@@ -337,10 +334,8 @@ func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
337 337
 // ([EnvOverrideAPIVersion]) environment variable, or if the client is initialized
338 338
 // with a fixed version ([WithVersion]), no negotiation is performed.
339 339
 //
340
-// If the API server's ping response does not contain an API version, we assume
341
-// we are connected with an old daemon without API version negotiation support,
342
-// and downgrade to the latest version of the API before version negotiation was
343
-// added (1.24).
340
+// If the API server's ping response does not contain an API version, it falls
341
+// back to the oldest API version supported.
344 342
 func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) {
345 343
 	if !cli.manualOverride {
346 344
 		// Avoid concurrent modification of version-related fields
... ...
@@ -355,8 +350,6 @@ func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) {
355 355
 // API version from the ping response.
356 356
 func (cli *Client) negotiateAPIVersionPing(pingVersion string) {
357 357
 	pingVersion = strings.TrimPrefix(pingVersion, "v")
358
-
359
-	// default to the latest version before versioning headers existed
360 358
 	if pingVersion == "" {
361 359
 		pingVersion = fallbackAPIVersion
362 360
 	}
... ...
@@ -303,9 +303,8 @@ func checkResponseErr(serverResp *http.Response) (retErr error) {
303 303
 			daemonErr = errors.New(strings.TrimSpace(errorResponse.Message))
304 304
 		}
305 305
 	} else {
306
-		// Fall back to returning the response as-is for API versions < 1.24
307
-		// that didn't support JSON error responses, and for situations
308
-		// where a plain text error is returned. This branch may also catch
306
+		// Fall back to returning the response as-is for situations where a
307
+		// plain text error is returned. This branch may also catch
309 308
 		// situations where a proxy is involved, returning a HTML response.
310 309
 		daemonErr = errors.New(strings.TrimSpace(string(body)))
311 310
 	}