mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
Add base cli and connection logic
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
be8e73292c
commit
37591c714b
5 changed files with 232 additions and 21 deletions
|
|
@ -27,21 +27,45 @@
|
|||
|
||||
package client
|
||||
|
||||
import "google.golang.org/grpc"
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
v1 "github.com/docker/api/backend/v1"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// NewContext is a context that is canceled when a signal is
|
||||
// sent to the process
|
||||
func NewContext() (context.Context, func()) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
s := make(chan os.Signal)
|
||||
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
|
||||
go func() {
|
||||
<-s
|
||||
cancel()
|
||||
}()
|
||||
return ctx, cancel
|
||||
}
|
||||
|
||||
// New returns a GRPC client
|
||||
func New(address string) (*Client, error) {
|
||||
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
||||
func New(address string, timeout time.Duration) (*Client, error) {
|
||||
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(timeout))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{
|
||||
conn: conn,
|
||||
conn: conn,
|
||||
BackendClient: v1.NewBackendClient(conn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
conn *grpc.ClientConn
|
||||
v1.BackendClient
|
||||
}
|
||||
|
||||
func (c *Client) Close() error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue