forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtgateconn.go
433 lines (362 loc) · 21.6 KB
/
vtgateconn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vtgateconn
import (
"flag"
"fmt"
"time"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/sqltypes"
"golang.org/x/net/context"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
vtgatepb "github.com/youtube/vitess/go/vt/proto/vtgate"
)
const (
// GoRPCProtocol is a vtgate protocol based on go rpc
GoRPCProtocol = "gorpc"
)
var (
// VtgateProtocol defines the RPC implementation used for connecting to vtgate.
VtgateProtocol = flag.String("vtgate_protocol", GoRPCProtocol, "how to talk to vtgate")
)
// VTGateConn is the client API object to talk to vtgate.
// It is constructed using the Dial method.
// It can be used concurrently across goroutines.
type VTGateConn struct {
impl Impl
}
// Execute executes a non-streaming query on vtgate.
// This is using v3 API.
func (conn *VTGateConn) Execute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
res, _, err := conn.impl.Execute(ctx, query, bindVars, tabletType, nil)
return res, err
}
// ExecuteShards executes a non-streaming query for multiple shards on vtgate.
func (conn *VTGateConn) ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
res, _, err := conn.impl.ExecuteShards(ctx, query, keyspace, shards, bindVars, tabletType, nil)
return res, err
}
// ExecuteKeyspaceIds executes a non-streaming query for multiple keyspace_ids.
func (conn *VTGateConn) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
res, _, err := conn.impl.ExecuteKeyspaceIds(ctx, query, keyspace, keyspaceIds, bindVars, tabletType, nil)
return res, err
}
// ExecuteKeyRanges executes a non-streaming query on a key range.
func (conn *VTGateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
res, _, err := conn.impl.ExecuteKeyRanges(ctx, query, keyspace, keyRanges, bindVars, tabletType, nil)
return res, err
}
// ExecuteEntityIds executes a non-streaming query for multiple entities.
func (conn *VTGateConn) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
res, _, err := conn.impl.ExecuteEntityIds(ctx, query, keyspace, entityColumnName, entityKeyspaceIDs, bindVars, tabletType, nil)
return res, err
}
// ExecuteBatchShards executes a set of non-streaming queries for multiple shards.
// If "asTransaction" is true, vtgate will automatically create a transaction
// (per shard) that encloses all the batch queries.
func (conn *VTGateConn) ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, asTransaction bool) ([]sqltypes.Result, error) {
res, _, err := conn.impl.ExecuteBatchShards(ctx, queries, tabletType, asTransaction, nil)
return res, err
}
// ExecuteBatchKeyspaceIds executes a set of non-streaming queries for multiple keyspace ids.
// If "asTransaction" is true, vtgate will automatically create a transaction
// (per shard) that encloses all the batch queries.
func (conn *VTGateConn) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtgatepb.BoundKeyspaceIdQuery, tabletType topodatapb.TabletType, asTransaction bool) ([]sqltypes.Result, error) {
res, _, err := conn.impl.ExecuteBatchKeyspaceIds(ctx, queries, tabletType, asTransaction, nil)
return res, err
}
// StreamExecute executes a streaming query on vtgate. It returns a
// channel, an ErrFunc, and error. First check the error. Then you can
// pull values from the channel till it's closed. Following this, you
// can call ErrFunc to see if the stream ended normally or due to a
// failure.
func (conn *VTGateConn) StreamExecute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecute(ctx, query, bindVars, tabletType)
}
// StreamExecute2 executes a streaming query on vtgate. It returns a
// channel, an ErrFunc, and error. First check the error. Then you can
// pull values from the channel till it's closed. Following this, you
// can call ErrFunc to see if the stream ended normally or due to a
// failure.
func (conn *VTGateConn) StreamExecute2(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecute2(ctx, query, bindVars, tabletType)
}
// StreamExecuteShards executes a streaming query on vtgate, on a set
// of shards. It returns a channel, an ErrFunc, and error. First
// check the error. Then you can pull values from the channel till
// it's closed. Following this, you can call ErrFunc to see if the
// stream ended normally or due to a failure.
func (conn *VTGateConn) StreamExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecuteShards(ctx, query, keyspace, shards, bindVars, tabletType)
}
// StreamExecuteShards2 executes a streaming query on vtgate, on a set
// of shards. It returns a channel, an ErrFunc, and error. First
// check the error. Then you can pull values from the channel till
// it's closed. Following this, you can call ErrFunc to see if the
// stream ended normally or due to a failure.
func (conn *VTGateConn) StreamExecuteShards2(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecuteShards2(ctx, query, keyspace, shards, bindVars, tabletType)
}
// StreamExecuteKeyRanges executes a streaming query on vtgate, on a
// set of keyranges. It returns a channel, an ErrFunc, and
// error. First check the error. Then you can pull values from the
// channel till it's closed. Following this, you can call ErrFunc to
// see if the stream ended normally or due to a failure.
func (conn *VTGateConn) StreamExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecuteKeyRanges(ctx, query, keyspace, keyRanges, bindVars, tabletType)
}
// StreamExecuteKeyRanges2 executes a streaming query on vtgate, on a
// set of keyranges. It returns a channel, an ErrFunc, and
// error. First check the error. Then you can pull values from the
// channel till it's closed. Following this, you can call ErrFunc to
// see if the stream ended normally or due to a failure.
func (conn *VTGateConn) StreamExecuteKeyRanges2(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecuteKeyRanges2(ctx, query, keyspace, keyRanges, bindVars, tabletType)
}
// StreamExecuteKeyspaceIds executes a streaming query on vtgate, for
// the given keyspaceIds. It returns a channel, an ErrFunc, and
// error. First check the error. Then you can pull values from the
// channel till it's closed. Following this, you can call ErrFunc to
// see if the stream ended normally or due to a failure.
func (conn *VTGateConn) StreamExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecuteKeyspaceIds(ctx, query, keyspace, keyspaceIds, bindVars, tabletType)
}
// StreamExecuteKeyspaceIds2 executes a streaming query on vtgate, for
// the given keyspaceIds. It returns a channel, an ErrFunc, and
// error. First check the error. Then you can pull values from the
// channel till it's closed. Following this, you can call ErrFunc to
// see if the stream ended normally or due to a failure.
func (conn *VTGateConn) StreamExecuteKeyspaceIds2(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error) {
return conn.impl.StreamExecuteKeyspaceIds2(ctx, query, keyspace, keyspaceIds, bindVars, tabletType)
}
// Begin starts a transaction and returns a VTGateTX.
func (conn *VTGateConn) Begin(ctx context.Context) (*VTGateTx, error) {
session, err := conn.impl.Begin(ctx)
if err != nil {
return nil, err
}
return &VTGateTx{
impl: conn.impl,
session: session,
}, nil
}
// Begin2 starts a transaction and returns a VTGateTX.
func (conn *VTGateConn) Begin2(ctx context.Context) (*VTGateTx, error) {
session, err := conn.impl.Begin2(ctx)
if err != nil {
return nil, err
}
return &VTGateTx{
impl: conn.impl,
session: session,
}, nil
}
// Close must be called for releasing resources.
func (conn *VTGateConn) Close() {
conn.impl.Close()
conn.impl = nil
}
// SplitQuery splits a query into equally sized smaller queries by
// appending primary key range clauses to the original query
func (conn *VTGateConn) SplitQuery(ctx context.Context, keyspace string, query string, bindVars map[string]interface{}, splitColumn string, splitCount int64) ([]*vtgatepb.SplitQueryResponse_Part, error) {
return conn.impl.SplitQuery(ctx, keyspace, query, bindVars, splitColumn, splitCount)
}
// GetSrvKeyspace returns a topo.SrvKeyspace object.
func (conn *VTGateConn) GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error) {
return conn.impl.GetSrvKeyspace(ctx, keyspace)
}
// VTGateTx defines an ongoing transaction.
// It should not be concurrently used across goroutines.
type VTGateTx struct {
impl Impl
session interface{}
}
// Execute executes a query on vtgate within the current transaction.
func (tx *VTGateTx) Execute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("execute: not in transaction")
}
res, session, err := tx.impl.Execute(ctx, query, bindVars, tabletType, tx.session)
tx.session = session
return res, err
}
// ExecuteShards executes a query for multiple shards on vtgate within the current transaction.
func (tx *VTGateTx) ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("executeShards: not in transaction")
}
res, session, err := tx.impl.ExecuteShards(ctx, query, keyspace, shards, bindVars, tabletType, tx.session)
tx.session = session
return res, err
}
// ExecuteKeyspaceIds executes a non-streaming query for multiple keyspace_ids.
func (tx *VTGateTx) ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("executeKeyspaceIds: not in transaction")
}
res, session, err := tx.impl.ExecuteKeyspaceIds(ctx, query, keyspace, keyspaceIds, bindVars, tabletType, tx.session)
tx.session = session
return res, err
}
// ExecuteKeyRanges executes a non-streaming query on a key range.
func (tx *VTGateTx) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("executeKeyRanges: not in transaction")
}
res, session, err := tx.impl.ExecuteKeyRanges(ctx, query, keyspace, keyRanges, bindVars, tabletType, tx.session)
tx.session = session
return res, err
}
// ExecuteEntityIds executes a non-streaming query for multiple entities.
func (tx *VTGateTx) ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (*sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("executeEntityIds: not in transaction")
}
res, session, err := tx.impl.ExecuteEntityIds(ctx, query, keyspace, entityColumnName, entityKeyspaceIDs, bindVars, tabletType, tx.session)
tx.session = session
return res, err
}
// ExecuteBatchShards executes a set of non-streaming queries for multiple shards.
func (tx *VTGateTx) ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType) ([]sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("executeBatchShards: not in transaction")
}
res, session, err := tx.impl.ExecuteBatchShards(ctx, queries, tabletType, false /* asTransaction */, tx.session)
tx.session = session
return res, err
}
// ExecuteBatchKeyspaceIds executes a set of non-streaming queries for multiple keyspace ids.
func (tx *VTGateTx) ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtgatepb.BoundKeyspaceIdQuery, tabletType topodatapb.TabletType) ([]sqltypes.Result, error) {
if tx.session == nil {
return nil, fmt.Errorf("executeBatchKeyspaceIds: not in transaction")
}
res, session, err := tx.impl.ExecuteBatchKeyspaceIds(ctx, queries, tabletType, false /* asTransaction */, tx.session)
tx.session = session
return res, err
}
// Commit commits the current transaction.
func (tx *VTGateTx) Commit(ctx context.Context) error {
if tx.session == nil {
return fmt.Errorf("commit: not in transaction")
}
err := tx.impl.Commit(ctx, tx.session)
tx.session = nil
return err
}
// Rollback rolls back the current transaction.
func (tx *VTGateTx) Rollback(ctx context.Context) error {
if tx.session == nil {
return nil
}
err := tx.impl.Rollback(ctx, tx.session)
tx.session = nil
return err
}
// Commit2 commits the current transaction.
func (tx *VTGateTx) Commit2(ctx context.Context) error {
if tx.session == nil {
return fmt.Errorf("commit: not in transaction")
}
err := tx.impl.Commit2(ctx, tx.session)
tx.session = nil
return err
}
// Rollback2 rolls back the current transaction.
func (tx *VTGateTx) Rollback2(ctx context.Context) error {
if tx.session == nil {
return nil
}
err := tx.impl.Rollback2(ctx, tx.session)
tx.session = nil
return err
}
// ErrFunc is used to check for streaming errors.
type ErrFunc func() error
//
// The rest of this file is for the protocol implementations.
//
// Impl defines the interface for a vtgate client protocol
// implementation. It can be used concurrently across goroutines.
type Impl interface {
// Execute executes a non-streaming query on vtgate.
Execute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType, session interface{}) (*sqltypes.Result, interface{}, error)
// ExecuteShards executes a non-streaming query for multiple shards on vtgate.
ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType, session interface{}) (*sqltypes.Result, interface{}, error)
// ExecuteKeyspaceIds executes a non-streaming query for multiple keyspace_ids.
ExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType, session interface{}) (*sqltypes.Result, interface{}, error)
// ExecuteKeyRanges executes a non-streaming query on a key range.
ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType, session interface{}) (*sqltypes.Result, interface{}, error)
// ExecuteEntityIds executes a non-streaming query for multiple entities.
ExecuteEntityIds(ctx context.Context, query string, keyspace string, entityColumnName string, entityKeyspaceIDs []*vtgatepb.ExecuteEntityIdsRequest_EntityId, bindVars map[string]interface{}, tabletType topodatapb.TabletType, session interface{}) (*sqltypes.Result, interface{}, error)
// ExecuteBatchShards executes a set of non-streaming queries for multiple shards.
ExecuteBatchShards(ctx context.Context, queries []*vtgatepb.BoundShardQuery, tabletType topodatapb.TabletType, asTransaction bool, session interface{}) ([]sqltypes.Result, interface{}, error)
// ExecuteBatchKeyspaceIds executes a set of non-streaming queries for multiple keyspace ids.
ExecuteBatchKeyspaceIds(ctx context.Context, queries []*vtgatepb.BoundKeyspaceIdQuery, tabletType topodatapb.TabletType, asTransaction bool, session interface{}) ([]sqltypes.Result, interface{}, error)
// StreamExecute executes a streaming query on vtgate.
StreamExecute(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecute2 executes a streaming query on vtgate.
StreamExecute2(ctx context.Context, query string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecuteShards executes a streaming query on vtgate, on a set of shards.
StreamExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecuteShards2 executes a streaming query on vtgate, on a set of shards.
StreamExecuteShards2(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecuteKeyRanges executes a streaming query on vtgate, on a set of keyranges.
StreamExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecuteKeyRanges2 executes a streaming query on vtgate, on a set of keyranges.
StreamExecuteKeyRanges2(ctx context.Context, query string, keyspace string, keyRanges []*topodatapb.KeyRange, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecuteKeyspaceIds executes a streaming query on vtgate, for the given keyspaceIds.
StreamExecuteKeyspaceIds(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// StreamExecuteKeyspaceIds2 executes a streaming query on vtgate, for the given keyspaceIds.
StreamExecuteKeyspaceIds2(ctx context.Context, query string, keyspace string, keyspaceIds [][]byte, bindVars map[string]interface{}, tabletType topodatapb.TabletType) (<-chan *sqltypes.Result, ErrFunc, error)
// Begin starts a transaction and returns a VTGateTX.
Begin(ctx context.Context) (interface{}, error)
// Commit commits the current transaction.
Commit(ctx context.Context, session interface{}) error
// Rollback rolls back the current transaction.
Rollback(ctx context.Context, session interface{}) error
// New methods (that don't quite work yet) which will eventually replace the existing ones:
// Begin starts a transaction and returns a VTGateTX.
Begin2(ctx context.Context) (interface{}, error)
// Commit commits the current transaction.
Commit2(ctx context.Context, session interface{}) error
// Rollback rolls back the current transaction.
Rollback2(ctx context.Context, session interface{}) error
// SplitQuery splits a query into equally sized smaller queries by
// appending primary key range clauses to the original query.
SplitQuery(ctx context.Context, keyspace string, query string, bindVars map[string]interface{}, splitColumn string, splitCount int64) ([]*vtgatepb.SplitQueryResponse_Part, error)
// GetSrvKeyspace returns a topo.SrvKeyspace.
GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error)
// Close must be called for releasing resources.
Close()
}
// DialerFunc represents a function that will return a VTGateConn object that can communicate with a VTGate.
type DialerFunc func(ctx context.Context, address string, timeout time.Duration) (Impl, error)
var dialers = make(map[string]DialerFunc)
// RegisterDialer is meant to be used by Dialer implementations
// to self register.
func RegisterDialer(name string, dialer DialerFunc) {
if _, ok := dialers[name]; ok {
log.Warningf("Dialer %s already exists, overwriting it", name)
}
dialers[name] = dialer
}
// DialProtocol dials a specific protocol, and returns the *VTGateConn
func DialProtocol(ctx context.Context, protocol string, address string, timeout time.Duration) (*VTGateConn, error) {
dialer, ok := dialers[protocol]
if !ok {
return nil, fmt.Errorf("no dialer registered for VTGate protocol %s", protocol)
}
impl, err := dialer(ctx, address, timeout)
if err != nil {
return nil, err
}
return &VTGateConn{
impl: impl,
}, nil
}
// Dial dials using the command-line specified protocol, and returns
// the *VTGateConn.
func Dial(ctx context.Context, address string, timeout time.Duration) (*VTGateConn, error) {
return DialProtocol(ctx, *VtgateProtocol, address, timeout)
}