Skip to content

Commit

Permalink
Merge pull request #5851 from jwhonce/wip/json
Browse files Browse the repository at this point in the history
Provide a json variable pointing to a configured json API
  • Loading branch information
openshift-merge-robot authored Apr 21, 2020
2 parents 02bd8ce + b21a5b7 commit ba1b5d4
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cmd/podman/common/default.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package common

import (
"github.com/containers/libpod/cmd/podman/registry"
)

var (
// DefaultHealthCheckInterval default value
DefaultHealthCheckInterval = "30s"
Expand All @@ -11,4 +15,6 @@ var (
DefaultHealthCheckTimeout = "30s"
// DefaultImageVolume default value
DefaultImageVolume = "bind"
// Pull in configured json library
json = registry.JsonLibrary()
)
1 change: 0 additions & 1 deletion cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package common

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

var (
// Pull in configured json library
json = registry.JsonLibrary()

// Command: podman _container_
containerCmd = &cobra.Command{
Use: "container",
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/containers/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 0 additions & 1 deletion cmd/podman/containers/mount.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package containers

import (
"encoding/json"
"fmt"
"os"
"text/tabwriter"
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package containers

import (
"encoding/json"
"fmt"
"os"
"sort"
Expand Down
2 changes: 0 additions & 2 deletions cmd/podman/images/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/images/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

var (
// Pull in configured json library
json = registry.JsonLibrary()

// Command: podman _image_
imageCmd = &cobra.Command{
Use: "image",
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/images/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package images

import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
Expand Down
2 changes: 0 additions & 2 deletions cmd/podman/images/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/pods/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/pods/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

var (
// Pull in configured json library
json = registry.JsonLibrary()

// Command: podman _pod_
podCmd = &cobra.Command{
Use: "pod",
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman/pods/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pods

import (
"context"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -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"
)
Expand Down
20 changes: 20 additions & 0 deletions cmd/podman/registry/json.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions cmd/podman/report/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/podman/report/report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package report

import "github.com/containers/libpod/cmd/podman/registry"

// Pull in configured json library
var json = registry.JsonLibrary()
1 change: 0 additions & 1 deletion cmd/podman/system/info.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package system

import (
"encoding/json"
"fmt"
"os"
"text/template"
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

var (
// Pull in configured json library
json = registry.JsonLibrary()

// Command: podman _system_
systemCmd = &cobra.Command{
Use: "system",
Expand Down
1 change: 0 additions & 1 deletion cmd/podman/volumes/inspect.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package volumes

import (
"encoding/json"
"fmt"
"html/template"
"os"
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/volumes/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

var (
// Pull in configured json library
json = registry.JsonLibrary()

// Command: podman _volume_
volumeCmd = &cobra.Command{
Use: "volume",
Expand Down

0 comments on commit ba1b5d4

Please sign in to comment.