mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +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
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultHealthCheckInterval default value
|
// DefaultHealthCheckInterval default value
|
||||||
DefaultHealthCheckInterval = "30s"
|
DefaultHealthCheckInterval = "30s"
|
||||||
@ -11,4 +15,6 @@ var (
|
|||||||
DefaultHealthCheckTimeout = "30s"
|
DefaultHealthCheckTimeout = "30s"
|
||||||
// DefaultImageVolume default value
|
// DefaultImageVolume default value
|
||||||
DefaultImageVolume = "bind"
|
DefaultImageVolume = "bind"
|
||||||
|
// Pull in configured json library
|
||||||
|
json = registry.JsonLibrary()
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -8,6 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Pull in configured json library
|
||||||
|
json = registry.JsonLibrary()
|
||||||
|
|
||||||
// Command: podman _container_
|
// Command: podman _container_
|
||||||
containerCmd = &cobra.Command{
|
containerCmd = &cobra.Command{
|
||||||
Use: "container",
|
Use: "container",
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
|
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
json "github.com/json-iterator/go"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package containers
|
package containers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package containers
|
package containers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -77,7 +76,6 @@ func history(cmd *cobra.Command, args []string) error {
|
|||||||
layers[i].ImageHistoryLayer = l
|
layers[i].ImageHistoryLayer = l
|
||||||
layers[i].Created = l.Created.Format(time.RFC3339)
|
layers[i].Created = l.Created.Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
|
||||||
enc := json.NewEncoder(os.Stdout)
|
enc := json.NewEncoder(os.Stdout)
|
||||||
err = enc.Encode(layers)
|
err = enc.Encode(layers)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Pull in configured json library
|
||||||
|
json = registry.JsonLibrary()
|
||||||
|
|
||||||
// Command: podman _image_
|
// Command: podman _image_
|
||||||
imageCmd = &cobra.Command{
|
imageCmd = &cobra.Command{
|
||||||
Use: "image",
|
Use: "image",
|
||||||
|
@ -2,7 +2,6 @@ package images
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
@ -127,7 +126,6 @@ func writeJSON(imageS []*entities.ImageSummary) error {
|
|||||||
imgs = append(imgs, h)
|
imgs = append(imgs, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
|
||||||
enc := json.NewEncoder(os.Stdout)
|
enc := json.NewEncoder(os.Stdout)
|
||||||
return enc.Encode(imgs)
|
return enc.Encode(imgs)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -55,7 +54,7 @@ func inspect(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b, err := jsoniter.MarshalIndent(responses, "", " ")
|
b, err := json.MarshalIndent(responses, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Pull in configured json library
|
||||||
|
json = registry.JsonLibrary()
|
||||||
|
|
||||||
// Command: podman _pod_
|
// Command: podman _pod_
|
||||||
podCmd = &cobra.Command{
|
podCmd = &cobra.Command{
|
||||||
Use: "pod",
|
Use: "pod",
|
||||||
|
@ -2,7 +2,6 @@ package pods
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -11,10 +10,9 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/go-units"
|
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
"github.com/containers/libpod/pkg/domain/entities"
|
"github.com/containers/libpod/pkg/domain/entities"
|
||||||
|
"github.com/docker/go-units"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"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/libpod/pkg/domain/entities"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/pkg/errors"
|
"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)
|
enc := json.NewEncoder(os.Stdout)
|
||||||
return enc.Encode(body)
|
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
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Pull in configured json library
|
||||||
|
json = registry.JsonLibrary()
|
||||||
|
|
||||||
// Command: podman _system_
|
// Command: podman _system_
|
||||||
systemCmd = &cobra.Command{
|
systemCmd = &cobra.Command{
|
||||||
Use: "system",
|
Use: "system",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package volumes
|
package volumes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"os"
|
"os"
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Pull in configured json library
|
||||||
|
json = registry.JsonLibrary()
|
||||||
|
|
||||||
// Command: podman _volume_
|
// Command: podman _volume_
|
||||||
volumeCmd = &cobra.Command{
|
volumeCmd = &cobra.Command{
|
||||||
Use: "volume",
|
Use: "volume",
|
||||||
|
Reference in New Issue
Block a user