mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
filters: use json marshal, instead of beam/data
Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
This commit is contained in:
parent
3ecfaa8f2d
commit
89a15fa235
3 changed files with 30 additions and 8 deletions
|
@ -1172,10 +1172,15 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|||
matchName := cmd.Arg(0)
|
||||
// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
||||
if *flViz || *flTree {
|
||||
filterJson, err := filters.ToParam(imageFilterArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v := url.Values{
|
||||
"all": []string{"1"},
|
||||
"filters": []string{filters.ToParam(imageFilterArgs)},
|
||||
"filters": []string{filterJson},
|
||||
}
|
||||
|
||||
body, _, err := readBody(cli.call("GET", "/images/json?"+v.Encode(), nil, false))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1237,9 +1242,14 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|||
fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
|
||||
}
|
||||
} else {
|
||||
v := url.Values{
|
||||
"filters": []string{filters.ToParam(imageFilterArgs)},
|
||||
filterJson, err := filters.ToParam(imageFilterArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v := url.Values{
|
||||
"filters": []string{filterJson},
|
||||
}
|
||||
|
||||
if cmd.NArg() == 1 {
|
||||
// FIXME rename this parameter, to not be confused with the filters flag
|
||||
v.Set("filter", matchName)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package filters
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/dotcloud/docker/pkg/beam/data"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -40,13 +40,22 @@ var ErrorBadFormat = errors.New("bad format of filter (expected name=value)")
|
|||
/*
|
||||
packs the Args into an string for easy transport from client to server
|
||||
*/
|
||||
func ToParam(a Args) string {
|
||||
return data.Encode(a)
|
||||
func ToParam(a Args) (string, error) {
|
||||
buf, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
/*
|
||||
unpacks the filter Args
|
||||
*/
|
||||
func FromParam(p string) (Args, error) {
|
||||
return data.Decode(p)
|
||||
args := Args{}
|
||||
err := json.Unmarshal([]byte(p), &args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return args, nil
|
||||
}
|
||||
|
|
|
@ -36,7 +36,10 @@ func TestParam(t *testing.T) {
|
|||
"image.name": []string{"ubuntu*", "*untu"},
|
||||
}
|
||||
|
||||
v := ToParam(a)
|
||||
v, err := ToParam(a)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal the filters: %s", err)
|
||||
}
|
||||
v1, err := FromParam(v)
|
||||
if err != nil {
|
||||
t.Errorf("%s", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue