mirror of
https://github.com/containers/podman.git
synced 2025-06-22 01:48:54 +08:00
Merge pull request #5851 from jwhonce/wip/json
Provide a json variable pointing to a configured json API
This commit is contained in:
@ -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()
|
||||
)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -8,6 +8,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Pull in configured json library
|
||||
json = registry.JsonLibrary()
|
||||
|
||||
// Command: podman _container_
|
||||
containerCmd = &cobra.Command{
|
||||
Use: "container",
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package containers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
@ -1,7 +1,6 @@
|
||||
package containers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Pull in configured json library
|
||||
json = registry.JsonLibrary()
|
||||
|
||||
// Command: podman _image_
|
||||
imageCmd = &cobra.Command{
|
||||
Use: "image",
|
||||
|
@ -2,7 +2,6 @@ package images
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Pull in configured json library
|
||||
json = registry.JsonLibrary()
|
||||
|
||||
// Command: podman _pod_
|
||||
podCmd = &cobra.Command{
|
||||
Use: "pod",
|
||||
|
@ -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"
|
||||
)
|
||||
|
20
cmd/podman/registry/json.go
Normal file
20
cmd/podman/registry/json.go
Normal 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
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
6
cmd/podman/report/report.go
Normal file
6
cmd/podman/report/report.go
Normal file
@ -0,0 +1,6 @@
|
||||
package report
|
||||
|
||||
import "github.com/containers/libpod/cmd/podman/registry"
|
||||
|
||||
// Pull in configured json library
|
||||
var json = registry.JsonLibrary()
|
@ -1,7 +1,6 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/template"
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Pull in configured json library
|
||||
json = registry.JsonLibrary()
|
||||
|
||||
// Command: podman _system_
|
||||
systemCmd = &cobra.Command{
|
||||
Use: "system",
|
||||
|
@ -1,7 +1,6 @@
|
||||
package volumes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Pull in configured json library
|
||||
json = registry.JsonLibrary()
|
||||
|
||||
// Command: podman _volume_
|
||||
volumeCmd = &cobra.Command{
|
||||
Use: "volume",
|
||||
|
Reference in New Issue
Block a user