Merge pull request #5851 from jwhonce/wip/json

Provide a json variable pointing to a configured json API
This commit is contained in:
OpenShift Merge Robot
2020-04-21 16:13:06 -04:00
committed by GitHub
20 changed files with 50 additions and 18 deletions

View File

@ -1,5 +1,9 @@
package common
import (
"github.com/containers/libpod/cmd/podman/registry"
)
var (
// DefaultHealthCheckInterval default value
DefaultHealthCheckInterval = "30s"
@ -11,4 +15,6 @@ var (
DefaultHealthCheckTimeout = "30s"
// DefaultImageVolume default value
DefaultImageVolume = "bind"
// Pull in configured json library
json = registry.JsonLibrary()
)

View File

@ -1,7 +1,6 @@
package common
import (
"encoding/json"
"fmt"
"os"
"path/filepath"

View File

@ -8,6 +8,9 @@ import (
)
var (
// Pull in configured json library
json = registry.JsonLibrary()
// Command: podman _container_
containerCmd = &cobra.Command{
Use: "container",

View File

@ -11,7 +11,6 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
json "github.com/json-iterator/go"
"github.com/spf13/cobra"
)

View File

@ -1,7 +1,6 @@
package containers
import (
"encoding/json"
"fmt"
"os"
"text/tabwriter"

View File

@ -1,7 +1,6 @@
package containers
import (
"encoding/json"
"fmt"
"os"
"sort"

View File

@ -13,7 +13,6 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/docker/go-units"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -77,7 +76,6 @@ func history(cmd *cobra.Command, args []string) error {
layers[i].ImageHistoryLayer = l
layers[i].Created = l.Created.Format(time.RFC3339)
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
enc := json.NewEncoder(os.Stdout)
err = enc.Encode(layers)
}

View File

@ -7,6 +7,9 @@ import (
)
var (
// Pull in configured json library
json = registry.JsonLibrary()
// Command: podman _image_
imageCmd = &cobra.Command{
Use: "image",

View File

@ -2,7 +2,6 @@ package images
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

View File

@ -14,7 +14,6 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/docker/go-units"
jsoniter "github.com/json-iterator/go"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -127,7 +126,6 @@ func writeJSON(imageS []*entities.ImageSummary) error {
imgs = append(imgs, h)
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
enc := json.NewEncoder(os.Stdout)
return enc.Encode(imgs)
}

View File

@ -6,7 +6,6 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -55,7 +54,7 @@ func inspect(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
b, err := jsoniter.MarshalIndent(responses, "", " ")
b, err := json.MarshalIndent(responses, "", " ")
if err != nil {
return err
}

View File

@ -8,6 +8,9 @@ import (
)
var (
// Pull in configured json library
json = registry.JsonLibrary()
// Command: podman _pod_
podCmd = &cobra.Command{
Use: "pod",

View File

@ -2,7 +2,6 @@ package pods
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
@ -11,10 +10,9 @@ import (
"text/template"
"time"
"github.com/docker/go-units"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

View File

@ -0,0 +1,20 @@
package registry
import (
"sync"
jsoniter "github.com/json-iterator/go"
)
var (
json jsoniter.API
jsonSync sync.Once
)
// JsonLibrary provides a "encoding/json" compatible API
func JsonLibrary() jsoniter.API {
jsonSync.Do(func() {
json = jsoniter.ConfigCompatibleWithStandardLibrary
})
return json
}

View File

@ -6,7 +6,6 @@ import (
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/storage/pkg/archive"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
@ -31,7 +30,7 @@ func ChangesToJSON(diffs *entities.DiffReport) error {
}
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
// Pull in configured json library
enc := json.NewEncoder(os.Stdout)
return enc.Encode(body)
}

View File

@ -0,0 +1,6 @@
package report
import "github.com/containers/libpod/cmd/podman/registry"
// Pull in configured json library
var json = registry.JsonLibrary()

View File

@ -1,7 +1,6 @@
package system
import (
"encoding/json"
"fmt"
"os"
"text/template"

View File

@ -7,6 +7,9 @@ import (
)
var (
// Pull in configured json library
json = registry.JsonLibrary()
// Command: podman _system_
systemCmd = &cobra.Command{
Use: "system",

View File

@ -1,7 +1,6 @@
package volumes
import (
"encoding/json"
"fmt"
"html/template"
"os"

View File

@ -7,6 +7,9 @@ import (
)
var (
// Pull in configured json library
json = registry.JsonLibrary()
// Command: podman _volume_
volumeCmd = &cobra.Command{
Use: "volume",