Răsfoiți Sursa

Remove useless client grpc stuff

Djordje Lukic 5 ani în urmă
părinte
comite
b2606b91f2
3 a modificat fișierele cu 5 adăugiri și 55 ștergeri
  1. 2 38
      cli/cmd/example.go
  2. 3 7
      cli/cmd/ps.go
  3. 0 10
      client/client.go

+ 2 - 38
cli/cmd/example.go

@@ -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) {

+ 3 - 7
cli/cmd/ps.go

@@ -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")
 		}

+ 0 - 10
client/client.go

@@ -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
-}