diff --git a/runtime/v2/bridge.go b/runtime/v2/bridge.go index 9d93a83a0..4075d6c2d 100644 --- a/runtime/v2/bridge.go +++ b/runtime/v2/bridge.go @@ -38,16 +38,14 @@ import ( // In 1.7 we support TaskService v2 (for backward compatibility with existing shims) and GRPC TaskService v3. // In 2.0 we'll switch to TaskService v3 only for both TTRPC and GRPC, which will remove overhead of mapping v2 structs to v3 structs. func NewTaskClient(client interface{}) (v2.TaskService, error) { - if ttrpcClient, ok := client.(*ttrpc.Client); ok { - return v2.NewTaskClient(ttrpcClient), nil + switch c := client.(type) { + case *ttrpc.Client: + return v2.NewTaskClient(c), nil + case grpc.ClientConnInterface: + return &grpcBridge{v3.NewTaskClient(c)}, nil + default: + return nil, fmt.Errorf("unsupported shim client type %T", c) } - - if grpcClient, ok := client.(grpc.ClientConnInterface); ok { - client := v3.NewTaskClient(grpcClient) - return &grpcBridge{client}, nil - } - - return nil, fmt.Errorf("unsupported shim client type %T", client) } // grpcBridge implements `v2.TaskService` interface for GRPC shim server. diff --git a/sandbox/bridge.go b/sandbox/bridge.go index 97a26a0b3..bc7d999ce 100644 --- a/sandbox/bridge.go +++ b/sandbox/bridge.go @@ -28,16 +28,14 @@ import ( // NewClient returns a new sandbox client that handles both GRPC and TTRPC clients. func NewClient(client interface{}) (api.TTRPCSandboxService, error) { - if ttrpcClient, ok := client.(*ttrpc.Client); ok { - return api.NewTTRPCSandboxClient(ttrpcClient), nil + switch c := client.(type) { + case *ttrpc.Client: + return api.NewTTRPCSandboxClient(c), nil + case grpc.ClientConnInterface: + return &grpcBridge{api.NewSandboxClient(c)}, nil + default: + return nil, fmt.Errorf("unsupported client type %T", client) } - - if grpcClient, ok := client.(grpc.ClientConnInterface); ok { - client := api.NewSandboxClient(grpcClient) - return &grpcBridge{client}, nil - } - - return nil, fmt.Errorf("unsupported client type %T", client) } type grpcBridge struct {