Remove useless client grpc stuff

This commit is contained in:
Djordje Lukic 2020-04-30 11:06:04 +02:00
parent f4bde8cb89
commit b2606b91f2
3 changed files with 5 additions and 55 deletions

View File

@ -31,7 +31,6 @@ import (
"context"
"encoding/json"
"os"
"os/exec"
"github.com/docker/api/client"
"github.com/golang/protobuf/ptypes/empty"
@ -45,16 +44,12 @@ var ExampleCommand = cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
// get our current context
ctx = current(ctx)
client, err := connect(ctx)
c, err := client.New(ctx)
if err != nil {
return errors.Wrap(err, "cannot connect to backend")
}
defer client.Close()
info, err := client.BackendInformation(ctx, &empty.Empty{})
info, err := c.BackendInformation(ctx, &empty.Empty{})
if err != nil {
return errors.Wrap(err, "fetch backend information")
}
@ -64,37 +59,6 @@ var ExampleCommand = cobra.Command{
},
}
// mock information for getting context
// factor out this into a context store package
func current(ctx context.Context) context.Context {
// test backend address
return context.WithValue(ctx, backendAddressKey{}, "/tmp/backend.sock")
}
func connect(ctx context.Context) (*client.Client, error) {
address, err := BackendAddress(ctx)
if err != nil {
return nil, errors.Wrap(err, "no backend address")
}
c, err := client.New(ctx)
if err != nil {
if err != context.DeadlineExceeded {
return nil, errors.Wrap(err, "connect to backend")
}
// the backend is not running so start it
cmd := exec.Command("backend-example", "--address", address)
go cmd.Wait()
if err := cmd.Start(); err != nil {
return nil, errors.Wrap(err, "start backend")
}
cl, e := client.New(ctx)
return cl, e
}
return c, nil
}
type backendAddressKey struct{}
func BackendAddress(ctx context.Context) (string, error) {

View File

@ -5,7 +5,7 @@ import (
"os"
"text/tabwriter"
client2 "github.com/docker/api/client"
"github.com/docker/api/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -16,16 +16,12 @@ var PsCommand = cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
// get our current context
ctx = current(ctx)
client, err := client2.New(ctx)
c, err := client.New(ctx)
if err != nil {
return errors.Wrap(err, "cannot connect to backend")
}
defer client.Close()
containers, err := client.ContainerService(ctx).List(ctx)
containers, err := c.ContainerService(ctx).List(ctx)
if err != nil {
return errors.Wrap(err, "fetch containers")
}

View File

@ -31,8 +31,6 @@ import (
"context"
"errors"
"google.golang.org/grpc"
"github.com/docker/api/backend"
v1 "github.com/docker/api/backend/v1"
"github.com/docker/api/containers"
@ -66,7 +64,6 @@ func New(ctx context.Context) (*Client, error) {
}
type Client struct {
conn *grpc.ClientConn
v1.BackendClient
backendType string
cc containers.ContainerService
@ -75,10 +72,3 @@ type Client struct {
func (c *Client) ContainerService(ctx context.Context) containers.ContainerService {
return c.cc
}
func (c *Client) Close() error {
if c.conn != nil {
return c.conn.Close()
}
return nil
}