diff options
author | Jhon Honce <jhonce@redhat.com> | 2020-11-17 11:41:51 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2020-11-17 11:45:03 -0700 |
commit | 4ed1ef533aac3a0262f6afe0fbac1f163e7d5706 (patch) | |
tree | 9fb408b5a78c4635bc762600e0dfbaadc2521b7f /cmd/podman | |
parent | 3a172c5999706e4493824c436bd7e2e8ea7b3d59 (diff) | |
download | podman-4ed1ef533aac3a0262f6afe0fbac1f163e7d5706.tar.gz podman-4ed1ef533aac3a0262f6afe0fbac1f163e7d5706.tar.bz2 podman-4ed1ef533aac3a0262f6afe0fbac1f163e7d5706.zip |
Swap out json-iterator for golang default
json-iterator library failed to pretty print json for all inspection
types.
Fixes #8366
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/inspect/inspect.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go index f9bd75c93..13f36ebbd 100644 --- a/cmd/podman/inspect/inspect.go +++ b/cmd/podman/inspect/inspect.go @@ -2,6 +2,7 @@ package inspect import ( "context" + "encoding/json" // due to a bug in json-iterator it cannot be used here "fmt" "os" "regexp" @@ -28,17 +29,14 @@ const ( ContainerType = "container" // ImageType is the image type. ImageType = "image" - //NetworkType is the network type + // NetworkType is the network type NetworkType = "network" - //PodType is the pod type. + // PodType is the pod type. PodType = "pod" - //VolumeType is the volume type + // VolumeType is the volume type VolumeType = "volume" ) -// Pull in configured json library -var json = registry.JSONLibrary() - // AddInspectFlagSet takes a command and adds the inspect flags and returns an // InspectOptions object. func AddInspectFlagSet(cmd *cobra.Command) *entities.InspectOptions { @@ -173,7 +171,7 @@ func (i *inspector) inspect(namesOrIDs []string) error { data = append(data, podData) } } - if i.podOptions.Latest { //latest means there are no names in the namesOrID array + if i.podOptions.Latest { // latest means there are no names in the namesOrID array podData, err := i.containerEngine.PodInspect(ctx, i.podOptions) if err != nil { cause := errors.Cause(err) @@ -238,9 +236,12 @@ func (i *inspector) inspect(namesOrIDs []string) error { } func printJSON(data []interface{}) error { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(data) + buf, err := json.MarshalIndent(data, "", " ") + if err != nil { + return err + } + _, err = fmt.Println(string(buf)) + return err } func printTmpl(typ, row string, data []interface{}) error { |