Skip to content

Commit

Permalink
Hiding public constructors that take a gRPC connection. (bazelbuild#83)
Browse files Browse the repository at this point in the history
Prepares for addition of a second connection to the CAS service in
DialParams (bazelbuild#78). Also adding better named overloads for constructors in
order to migrate users to these names.
  • Loading branch information
Ola Rozenfeld authored Oct 18, 2019
1 parent f451657 commit 42f9c10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
24 changes: 15 additions & 9 deletions go/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,20 @@ func DialRaw(ctx context.Context, params DialParams) (*grpc.ClientConn, error) {

// Dial dials a remote execution service and returns a client suitable for higher-level
// functionality.
// TODO(olaola): rename to separate creating a gRPC connection from creating a Client:
// Dial -> NewClient
// DialFromFlags -> NewClientFromFlags
// DialRaw -> Dial
// TODO(olaola): remove this overload when everyone uses NewClient.
func Dial(ctx context.Context, instanceName string, params DialParams, opts ...Opt) (*Client, error) {
conn, err := DialRaw(ctx, params)
if err != nil {
return nil, err
}
return NewClient(conn, instanceName, opts...)
}

// NewClient creates a client from an existing gRPC connection.
func NewClient(conn *grpc.ClientConn, instanceName string, opts ...Opt) (*Client, error) {
if instanceName == "" {
return nil, fmt.Errorf("instance needs to be specified")
}
log.Infof("Connecting to remote execution instance %s", instanceName)
conn, err := DialRaw(ctx, params)
if err != nil {
return nil, err
}
client := &Client{
InstanceName: instanceName,
actionCache: regrpc.NewActionCacheClient(conn),
Expand All @@ -249,6 +249,12 @@ func NewClient(conn *grpc.ClientConn, instanceName string, opts ...Opt) (*Client
return client, nil
}

// NewClient connects to a remote execution service and returns a Client suitable
// for higher-level functionality.
func NewClient(ctx context.Context, instanceName string, params DialParams, opts ...Opt) (*Client, error) {
return Dial(ctx, instanceName, params, opts...)
}

// RPCTimeout is a Opt that sets the per-RPC deadline.
// NOTE that the deadline is only applied to non-streaming calls.
// The default timeout value is 1 minute.
Expand Down
8 changes: 8 additions & 0 deletions go/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (

// DialFromFlags dials a remote execution service and returns a client suitable for higher-level
// functionality. It uses the flags from above to configure the connection to remote execution.
// TODO(olaola): remove this overload when everyone uses NewClientFromFlags.
func DialFromFlags(ctx context.Context, opts ...client.Opt) (*client.Client, error) {
return client.Dial(ctx, *Instance, client.DialParams{
Service: *Service,
Expand All @@ -45,3 +46,10 @@ func DialFromFlags(ctx context.Context, opts ...client.Opt) (*client.Client, err
UseComputeEngine: *UseGCECredentials,
}, opts...)
}

// NewClientFromFlags connects to a remote execution service and returns a client
// suitable for higher-level functionality. It uses the flags from above to configure
// the connection to remote execution.
func NewClientFromFlags(ctx context.Context, opts ...client.Opt) (*client.Client, error) {
return DialFromFlags(ctx, opts...)
}

0 comments on commit 42f9c10

Please sign in to comment.