From ddbb503dc724245b87eb7a650c544b2883a185ac Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 24 Oct 2025 19:07:26 +0200 Subject: [PATCH] client: change Raw fields to be json.RawMessage These fields store the raw JSON data that we received, and should never container bytes that are non-JSON (as we'd error out when failing to unmarshal). Change the type to a json.RawMessage, which: - Is more explicit on intent - Can still be used as a regular []byte in all cases And, while it's not expected to be marshaled to JSON, doing so will also print the output in a readable format instead of base64 encoding; package main import ( "encoding/json" "fmt" ) func main() { foo := struct { Bytes []byte Raw json.RawMessage }{ Bytes: []byte(`{"hello": "world"}`), Raw: json.RawMessage(`{"hello": "world"}`), } out, _ := json.MarshalIndent(foo, "", " ") fmt.Println(string(out)) } Will print: { "Bytes": "eyJoZWxsbyI6ICJ3b3JsZCJ9", "Raw": { "hello": "world" } } Signed-off-by: Sebastiaan van Stijn --- client/config_inspect.go | 3 ++- client/network_inspect.go | 3 ++- client/node_inspect.go | 2 +- client/plugin_inspect.go | 3 ++- client/secret_inspect.go | 3 ++- client/service_inspect.go | 3 ++- client/task_inspect.go | 3 ++- client/utils.go | 2 +- client/volume_inspect.go | 3 ++- vendor/github.com/moby/moby/client/config_inspect.go | 3 ++- vendor/github.com/moby/moby/client/network_inspect.go | 3 ++- vendor/github.com/moby/moby/client/node_inspect.go | 2 +- vendor/github.com/moby/moby/client/plugin_inspect.go | 3 ++- vendor/github.com/moby/moby/client/secret_inspect.go | 3 ++- vendor/github.com/moby/moby/client/service_inspect.go | 3 ++- vendor/github.com/moby/moby/client/task_inspect.go | 3 ++- vendor/github.com/moby/moby/client/utils.go | 2 +- vendor/github.com/moby/moby/client/volume_inspect.go | 3 ++- 18 files changed, 32 insertions(+), 18 deletions(-) diff --git a/client/config_inspect.go b/client/config_inspect.go index f1aaf68d98..d048a21b7b 100644 --- a/client/config_inspect.go +++ b/client/config_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/swarm" ) @@ -14,7 +15,7 @@ type ConfigInspectOptions struct { // ConfigInspectResult holds the result from the ConfigInspect method. type ConfigInspectResult struct { Config swarm.Config - Raw []byte + Raw json.RawMessage } // ConfigInspect returns the config information with raw data diff --git a/client/network_inspect.go b/client/network_inspect.go index 165aa5b465..34c156d679 100644 --- a/client/network_inspect.go +++ b/client/network_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "net/url" "github.com/moby/moby/api/types/network" @@ -10,7 +11,7 @@ import ( // NetworkInspectResult contains the result of a network inspection. type NetworkInspectResult struct { Network network.Inspect - Raw []byte + Raw json.RawMessage } // NetworkInspect returns the information for a specific network configured in the docker host. diff --git a/client/node_inspect.go b/client/node_inspect.go index 2fee09fd5e..cd4ce0119f 100644 --- a/client/node_inspect.go +++ b/client/node_inspect.go @@ -14,7 +14,7 @@ type NodeInspectOptions struct{} type NodeInspectResult struct { Node swarm.Node - Raw []byte + Raw json.RawMessage } // NodeInspect returns the node information. diff --git a/client/plugin_inspect.go b/client/plugin_inspect.go index e6853e644d..2837624a50 100644 --- a/client/plugin_inspect.go +++ b/client/plugin_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/plugin" ) @@ -13,8 +14,8 @@ type PluginInspectOptions struct { // PluginInspectResult holds the result from the [Client.PluginInspect] method. type PluginInspectResult struct { - Raw []byte Plugin plugin.Plugin + Raw json.RawMessage } // PluginInspect inspects an existing plugin diff --git a/client/secret_inspect.go b/client/secret_inspect.go index 360085215a..ad0998fa6a 100644 --- a/client/secret_inspect.go +++ b/client/secret_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/swarm" ) @@ -14,7 +15,7 @@ type SecretInspectOptions struct { // SecretInspectResult holds the result from the [Client.SecretInspect]. method. type SecretInspectResult struct { Secret swarm.Secret - Raw []byte + Raw json.RawMessage } // SecretInspect returns the secret information with raw data. diff --git a/client/service_inspect.go b/client/service_inspect.go index fabae9fb08..7075b68bb2 100644 --- a/client/service_inspect.go +++ b/client/service_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "fmt" "net/url" @@ -16,7 +17,7 @@ type ServiceInspectOptions struct { // ServiceInspectResult represents the result of a service inspect operation. type ServiceInspectResult struct { Service swarm.Service - Raw []byte + Raw json.RawMessage } // ServiceInspect retrieves detailed information about a specific service by its ID. diff --git a/client/task_inspect.go b/client/task_inspect.go index 277b00ff49..a79a3ba6a6 100644 --- a/client/task_inspect.go +++ b/client/task_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/swarm" ) @@ -14,7 +15,7 @@ type TaskInspectOptions struct { // TaskInspectResult contains the result of a task inspection. type TaskInspectResult struct { Task swarm.Task - Raw []byte + Raw json.RawMessage } // TaskInspect returns the task information and its raw representation. diff --git a/client/utils.go b/client/utils.go index 1da948b6c8..7359c27bda 100644 --- a/client/utils.go +++ b/client/utils.go @@ -70,7 +70,7 @@ func encodePlatform(platform *ocispec.Platform) (string, error) { return string(p), nil } -func decodeWithRaw[T any](resp *http.Response, out *T) (raw []byte, _ error) { +func decodeWithRaw[T any](resp *http.Response, out *T) (raw json.RawMessage, _ error) { if resp == nil || resp.Body == nil { return nil, errors.New("empty response") } diff --git a/client/volume_inspect.go b/client/volume_inspect.go index 1fa62bd9ec..621eb27ef1 100644 --- a/client/volume_inspect.go +++ b/client/volume_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/volume" ) @@ -13,8 +14,8 @@ type VolumeInspectOptions struct { // VolumeInspectResult holds the result from the [Client.VolumeInspect] method. type VolumeInspectResult struct { - Raw []byte Volume volume.Volume + Raw json.RawMessage } // VolumeInspect returns the information about a specific volume in the docker host. diff --git a/vendor/github.com/moby/moby/client/config_inspect.go b/vendor/github.com/moby/moby/client/config_inspect.go index f1aaf68d98..d048a21b7b 100644 --- a/vendor/github.com/moby/moby/client/config_inspect.go +++ b/vendor/github.com/moby/moby/client/config_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/swarm" ) @@ -14,7 +15,7 @@ type ConfigInspectOptions struct { // ConfigInspectResult holds the result from the ConfigInspect method. type ConfigInspectResult struct { Config swarm.Config - Raw []byte + Raw json.RawMessage } // ConfigInspect returns the config information with raw data diff --git a/vendor/github.com/moby/moby/client/network_inspect.go b/vendor/github.com/moby/moby/client/network_inspect.go index 165aa5b465..34c156d679 100644 --- a/vendor/github.com/moby/moby/client/network_inspect.go +++ b/vendor/github.com/moby/moby/client/network_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "net/url" "github.com/moby/moby/api/types/network" @@ -10,7 +11,7 @@ import ( // NetworkInspectResult contains the result of a network inspection. type NetworkInspectResult struct { Network network.Inspect - Raw []byte + Raw json.RawMessage } // NetworkInspect returns the information for a specific network configured in the docker host. diff --git a/vendor/github.com/moby/moby/client/node_inspect.go b/vendor/github.com/moby/moby/client/node_inspect.go index 2fee09fd5e..cd4ce0119f 100644 --- a/vendor/github.com/moby/moby/client/node_inspect.go +++ b/vendor/github.com/moby/moby/client/node_inspect.go @@ -14,7 +14,7 @@ type NodeInspectOptions struct{} type NodeInspectResult struct { Node swarm.Node - Raw []byte + Raw json.RawMessage } // NodeInspect returns the node information. diff --git a/vendor/github.com/moby/moby/client/plugin_inspect.go b/vendor/github.com/moby/moby/client/plugin_inspect.go index e6853e644d..2837624a50 100644 --- a/vendor/github.com/moby/moby/client/plugin_inspect.go +++ b/vendor/github.com/moby/moby/client/plugin_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/plugin" ) @@ -13,8 +14,8 @@ type PluginInspectOptions struct { // PluginInspectResult holds the result from the [Client.PluginInspect] method. type PluginInspectResult struct { - Raw []byte Plugin plugin.Plugin + Raw json.RawMessage } // PluginInspect inspects an existing plugin diff --git a/vendor/github.com/moby/moby/client/secret_inspect.go b/vendor/github.com/moby/moby/client/secret_inspect.go index 360085215a..ad0998fa6a 100644 --- a/vendor/github.com/moby/moby/client/secret_inspect.go +++ b/vendor/github.com/moby/moby/client/secret_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/swarm" ) @@ -14,7 +15,7 @@ type SecretInspectOptions struct { // SecretInspectResult holds the result from the [Client.SecretInspect]. method. type SecretInspectResult struct { Secret swarm.Secret - Raw []byte + Raw json.RawMessage } // SecretInspect returns the secret information with raw data. diff --git a/vendor/github.com/moby/moby/client/service_inspect.go b/vendor/github.com/moby/moby/client/service_inspect.go index fabae9fb08..7075b68bb2 100644 --- a/vendor/github.com/moby/moby/client/service_inspect.go +++ b/vendor/github.com/moby/moby/client/service_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "fmt" "net/url" @@ -16,7 +17,7 @@ type ServiceInspectOptions struct { // ServiceInspectResult represents the result of a service inspect operation. type ServiceInspectResult struct { Service swarm.Service - Raw []byte + Raw json.RawMessage } // ServiceInspect retrieves detailed information about a specific service by its ID. diff --git a/vendor/github.com/moby/moby/client/task_inspect.go b/vendor/github.com/moby/moby/client/task_inspect.go index 277b00ff49..a79a3ba6a6 100644 --- a/vendor/github.com/moby/moby/client/task_inspect.go +++ b/vendor/github.com/moby/moby/client/task_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/swarm" ) @@ -14,7 +15,7 @@ type TaskInspectOptions struct { // TaskInspectResult contains the result of a task inspection. type TaskInspectResult struct { Task swarm.Task - Raw []byte + Raw json.RawMessage } // TaskInspect returns the task information and its raw representation. diff --git a/vendor/github.com/moby/moby/client/utils.go b/vendor/github.com/moby/moby/client/utils.go index 1da948b6c8..7359c27bda 100644 --- a/vendor/github.com/moby/moby/client/utils.go +++ b/vendor/github.com/moby/moby/client/utils.go @@ -70,7 +70,7 @@ func encodePlatform(platform *ocispec.Platform) (string, error) { return string(p), nil } -func decodeWithRaw[T any](resp *http.Response, out *T) (raw []byte, _ error) { +func decodeWithRaw[T any](resp *http.Response, out *T) (raw json.RawMessage, _ error) { if resp == nil || resp.Body == nil { return nil, errors.New("empty response") } diff --git a/vendor/github.com/moby/moby/client/volume_inspect.go b/vendor/github.com/moby/moby/client/volume_inspect.go index 1fa62bd9ec..621eb27ef1 100644 --- a/vendor/github.com/moby/moby/client/volume_inspect.go +++ b/vendor/github.com/moby/moby/client/volume_inspect.go @@ -2,6 +2,7 @@ package client import ( "context" + "encoding/json" "github.com/moby/moby/api/types/volume" ) @@ -13,8 +14,8 @@ type VolumeInspectOptions struct { // VolumeInspectResult holds the result from the [Client.VolumeInspect] method. type VolumeInspectResult struct { - Raw []byte Volume volume.Volume + Raw json.RawMessage } // VolumeInspect returns the information about a specific volume in the docker host.