mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
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 <github@gone.nl>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -14,7 +14,7 @@ type NodeInspectOptions struct{}
|
||||
|
||||
type NodeInspectResult struct {
|
||||
Node swarm.Node
|
||||
Raw []byte
|
||||
Raw json.RawMessage
|
||||
}
|
||||
|
||||
// NodeInspect returns the node information.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
3
vendor/github.com/moby/moby/client/config_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/config_inspect.go
generated
vendored
@@ -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
|
||||
|
||||
3
vendor/github.com/moby/moby/client/network_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/network_inspect.go
generated
vendored
@@ -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.
|
||||
|
||||
2
vendor/github.com/moby/moby/client/node_inspect.go
generated
vendored
2
vendor/github.com/moby/moby/client/node_inspect.go
generated
vendored
@@ -14,7 +14,7 @@ type NodeInspectOptions struct{}
|
||||
|
||||
type NodeInspectResult struct {
|
||||
Node swarm.Node
|
||||
Raw []byte
|
||||
Raw json.RawMessage
|
||||
}
|
||||
|
||||
// NodeInspect returns the node information.
|
||||
|
||||
3
vendor/github.com/moby/moby/client/plugin_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/plugin_inspect.go
generated
vendored
@@ -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
|
||||
|
||||
3
vendor/github.com/moby/moby/client/secret_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/secret_inspect.go
generated
vendored
@@ -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.
|
||||
|
||||
3
vendor/github.com/moby/moby/client/service_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/service_inspect.go
generated
vendored
@@ -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.
|
||||
|
||||
3
vendor/github.com/moby/moby/client/task_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/task_inspect.go
generated
vendored
@@ -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.
|
||||
|
||||
2
vendor/github.com/moby/moby/client/utils.go
generated
vendored
2
vendor/github.com/moby/moby/client/utils.go
generated
vendored
@@ -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")
|
||||
}
|
||||
|
||||
3
vendor/github.com/moby/moby/client/volume_inspect.go
generated
vendored
3
vendor/github.com/moby/moby/client/volume_inspect.go
generated
vendored
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user