本文整理汇总了Golang中github.com/youtube/vitess/go/rpcwrap/bsonrpc.DialHTTP函数的典型用法代码示例。如果您正苦于以下问题:Golang DialHTTP函数的具体用法?Golang DialHTTP怎么用?Golang DialHTTP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DialHTTP函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: rpcCallTablet
// rpcCallTablet wil execute the RPC on the remote server.
func (client *GoRPCTabletManagerClient) rpcCallTablet(ctx context.Context, tablet *topo.TabletInfo, name string, args, reply interface{}) error {
// create the RPC client, using ctx.Deadline if set, or no timeout.
var connectTimeout time.Duration
deadline, ok := ctx.Deadline()
if ok {
connectTimeout = deadline.Sub(time.Now())
if connectTimeout < 0 {
return timeoutError{fmt.Errorf("timeout connecting to TabletManager.%v on %v", name, tablet.Alias)}
}
}
rpcClient, err := bsonrpc.DialHTTP("tcp", tablet.Addr(), connectTimeout)
if err != nil {
return fmt.Errorf("RPC error for %v: %v", tablet.Alias, err.Error())
}
defer rpcClient.Close()
// use the context Done() channel. Will handle context timeout.
call := rpcClient.Go(ctx, "TabletManager."+name, args, reply, nil)
select {
case <-ctx.Done():
if ctx.Err() == context.DeadlineExceeded {
return timeoutError{fmt.Errorf("timeout waiting for TabletManager.%v to %v", name, tablet.Alias)}
}
return fmt.Errorf("interrupted waiting for TabletManager.%v to %v", name, tablet.Alias)
case <-call.Done:
if call.Error != nil {
return fmt.Errorf("remote error for %v: %v", tablet.Alias, call.Error.Error())
}
return nil
}
}
开发者ID:richarwu,项目名称:vitess,代码行数:32,代码来源:gorpc_client.go
示例2: DialTablet
// DialTablet creates and initializes TabletBson.
func DialTablet(ctx context.Context, endPoint topo.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) {
var addr string
var config *tls.Config
if *tabletBsonEncrypted {
addr = netutil.JoinHostPort(endPoint.Host, endPoint.NamedPortMap["vts"])
config = &tls.Config{}
config.InsecureSkipVerify = true
} else {
addr = netutil.JoinHostPort(endPoint.Host, endPoint.NamedPortMap["vt"])
}
conn := &TabletBson{endPoint: endPoint}
var err error
if *tabletBsonUsername != "" {
conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, *tabletBsonUsername, *tabletBsonPassword, timeout, config)
} else {
conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, timeout, config)
}
if err != nil {
return nil, tabletError(err)
}
var sessionInfo tproto.SessionInfo
if err = conn.rpcClient.Call(ctx, "SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil {
conn.rpcClient.Close()
return nil, tabletError(err)
}
// SqlQuery.GetSessionId might return an application error inside the SessionInfo
if err = vterrors.FromRPCError(sessionInfo.Err); err != nil {
conn.rpcClient.Close()
return nil, tabletError(err)
}
conn.sessionID = sessionInfo.SessionId
return conn, nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:36,代码来源:conn.go
示例3: MultiSnapshot
func (client *GoRpcTabletManagerClient) MultiSnapshot(tablet *topo.TabletInfo, sa *actionnode.MultiSnapshotArgs, waitTime time.Duration) (<-chan *logutil.LoggerEvent, tmclient.MultiSnapshotReplyFunc, error) {
rpcClient, err := bsonrpc.DialHTTP("tcp", tablet.Addr(), waitTime, nil)
if err != nil {
return nil, nil, err
}
logstream := make(chan *logutil.LoggerEvent, 10)
rpcstream := make(chan *gorpcproto.MultiSnapshotStreamingReply, 10)
result := &actionnode.MultiSnapshotReply{}
c := rpcClient.StreamGo("TabletManager.MultiSnapshot", sa, rpcstream)
go func() {
for ssr := range rpcstream {
if ssr.Log != nil {
logstream <- ssr.Log
}
if ssr.Result != nil {
*result = *ssr.Result
}
}
close(logstream)
rpcClient.Close()
}()
return logstream, func() (*actionnode.MultiSnapshotReply, error) {
return result, c.Error
}, nil
}
开发者ID:plobsing,项目名称:vitess,代码行数:27,代码来源:gorpc_client.go
示例4: DialTablet
// DialTablet creates and initializes TabletBson.
func DialTablet(ctx context.Context, endPoint *pbt.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) {
addr := netutil.JoinHostPort(endPoint.Host, endPoint.PortMap["vt"])
conn := &TabletBson{endPoint: endPoint}
var err error
if *tabletBsonUsername != "" {
conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, *tabletBsonUsername, *tabletBsonPassword, timeout)
} else {
conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, timeout)
}
if err != nil {
return nil, tabletError(err)
}
if keyspace != "" || shard != "" {
var sessionInfo tproto.SessionInfo
if err = conn.rpcClient.Call(ctx, "SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil {
conn.rpcClient.Close()
return nil, tabletError(err)
}
// SqlQuery.GetSessionId might return an application error inside the SessionInfo
if err = vterrors.FromRPCError(sessionInfo.Err); err != nil {
conn.rpcClient.Close()
return nil, tabletError(err)
}
conn.sessionID = sessionInfo.SessionId
}
return conn, nil
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:29,代码来源:conn.go
示例5: DialTablet
// DialTablet creates and initializes TabletBson.
func DialTablet(context context.Context, endPoint topo.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) {
var addr string
var config *tls.Config
if *tabletBsonEncrypted {
addr = fmt.Sprintf("%v:%v", endPoint.Host, endPoint.NamedPortMap["_vts"])
config = &tls.Config{}
config.InsecureSkipVerify = true
} else {
addr = fmt.Sprintf("%v:%v", endPoint.Host, endPoint.NamedPortMap["_vtocc"])
}
conn := &TabletBson{endPoint: endPoint}
var err error
if *tabletBsonUsername != "" {
conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, *tabletBsonUsername, *tabletBsonPassword, timeout, config)
} else {
conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, timeout, config)
}
if err != nil {
return nil, tabletError(err)
}
var sessionInfo tproto.SessionInfo
if err = conn.rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil {
conn.rpcClient.Close()
return nil, tabletError(err)
}
conn.sessionID = sessionInfo.SessionId
return conn, nil
}
开发者ID:chinna1986,项目名称:vitess,代码行数:31,代码来源:conn.go
示例6: connect
func connect() *rpcplus.Client {
rpcClient, err := bsonrpc.DialHTTP("tcp", *server, 0, nil)
if err != nil {
log.Fatalf("Can't connect to zkocc: %v", err)
}
return rpcClient
}
开发者ID:nimishzynga,项目名称:vitess,代码行数:7,代码来源:zkclient2.go
示例7: goRPCVtctlClientFactory
func goRPCVtctlClientFactory(addr string, dialTimeout time.Duration) (vtctlclient.VtctlClient, error) {
// create the RPC client
rpcClient, err := bsonrpc.DialHTTP("tcp", addr, dialTimeout)
if err != nil {
return nil, fmt.Errorf("RPC error for %v: %v", addr, err)
}
return &goRPCVtctlClient{rpcClient}, nil
}
开发者ID:richarwu,项目名称:vitess,代码行数:9,代码来源:client.go
示例8: goRPCMysqlctlClientFactory
func goRPCMysqlctlClientFactory(network, addr string, dialTimeout time.Duration) (mysqlctlclient.MysqlctlClient, error) {
// create the RPC client
rpcClient, err := bsonrpc.DialHTTP(network, addr, dialTimeout, nil)
if err != nil {
return nil, fmt.Errorf("RPC error for %v: %v", addr, err)
}
return &goRPCMysqlctlClient{rpcClient}, nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:9,代码来源:client.go
示例9: dial
func dial(ctx context.Context, address string, timeout time.Duration) (vtgateconn.Impl, error) {
network := "tcp"
if strings.Contains(address, "/") {
network = "unix"
}
rpcConn, err := bsonrpc.DialHTTP(network, address, timeout)
if err != nil {
return nil, err
}
return &vtgateConn{rpcConn: rpcConn}, nil
}
开发者ID:payintel,项目名称:vitess,代码行数:11,代码来源:conn.go
示例10: MultiRestore
func (client *GoRpcTabletManagerClient) MultiRestore(tablet *topo.TabletInfo, sa *actionnode.MultiRestoreArgs, waitTime time.Duration) (<-chan *logutil.LoggerEvent, tmclient.ErrFunc, error) {
rpcClient, err := bsonrpc.DialHTTP("tcp", tablet.Addr(), waitTime, nil)
if err != nil {
return nil, nil, err
}
logstream := make(chan *logutil.LoggerEvent, 10)
c := rpcClient.StreamGo("TabletManager.MultiRestore", sa, logstream)
return logstream, func() error {
rpcClient.Close()
return c.Error
}, nil
}
开发者ID:plobsing,项目名称:vitess,代码行数:13,代码来源:gorpc_client.go
示例11: DialZkocc
// From the addr (of the form server1:port1,server2:port2,server3:port3:...)
// splits it on commas, randomizes the list, and tries to connect
// to the servers, stopping at the first successful connection
func DialZkocc(addr string, connectTimeout time.Duration) (zkocc *ZkoccConn, err error) {
servers := strings.Split(addr, ",")
perm := rand.Perm(len(servers))
for _, index := range perm {
server := servers[index]
rpcClient, err := bsonrpc.DialHTTP("tcp", server, connectTimeout, nil)
if err == nil {
return &ZkoccConn{rpcClient: rpcClient}, nil
}
log.Infof("zk conn cache: zkocc connection to %v failed: %v", server, err)
}
return nil, fmt.Errorf("zkocc connect failed: %v", addr)
}
开发者ID:chinna1986,项目名称:vitess,代码行数:17,代码来源:zkoccconn.go
示例12: Backup
// Backup is part of the tmclient.TabletManagerClient interface
func (client *GoRPCTabletManagerClient) Backup(ctx context.Context, tablet *topo.TabletInfo, concurrency int) (<-chan *logutil.LoggerEvent, tmclient.ErrFunc, error) {
var connectTimeout time.Duration
deadline, ok := ctx.Deadline()
if ok {
connectTimeout = deadline.Sub(time.Now())
if connectTimeout < 0 {
return nil, nil, timeoutError{fmt.Errorf("timeout connecting to TabletManager.Backup on %v", tablet.Alias)}
}
}
rpcClient, err := bsonrpc.DialHTTP("tcp", tablet.Addr(), connectTimeout)
if err != nil {
return nil, nil, err
}
logstream := make(chan *logutil.LoggerEvent, 10)
rpcstream := make(chan *logutil.LoggerEvent, 10)
c := rpcClient.StreamGo("TabletManager.Backup", &gorpcproto.BackupArgs{
Concurrency: concurrency,
}, rpcstream)
interrupted := false
go func() {
for {
select {
case <-ctx.Done():
// context is done
interrupted = true
close(logstream)
rpcClient.Close()
return
case ssr, ok := <-rpcstream:
if !ok {
close(logstream)
rpcClient.Close()
return
}
logstream <- ssr
}
}
}()
return logstream, func() error {
// this is only called after streaming is done
if interrupted {
return fmt.Errorf("TabletManager.Backup interrupted by context")
}
return c.Error
}, nil
}
开发者ID:richarwu,项目名称:vitess,代码行数:48,代码来源:gorpc_client.go
示例13: HealthStream
// HealthStream is part of the tmclient.TabletManagerClient interface
func (client *GoRPCTabletManagerClient) HealthStream(ctx context.Context, tablet *topo.TabletInfo) (<-chan *actionnode.HealthStreamReply, tmclient.ErrFunc, error) {
var connectTimeout time.Duration
deadline, ok := ctx.Deadline()
if ok {
connectTimeout = deadline.Sub(time.Now())
if connectTimeout < 0 {
return nil, nil, timeoutError{fmt.Errorf("timeout connecting to TabletManager.HealthStream on %v", tablet.Alias)}
}
}
rpcClient, err := bsonrpc.DialHTTP("tcp", tablet.Addr(), connectTimeout, nil)
if err != nil {
return nil, nil, err
}
logstream := make(chan *actionnode.HealthStreamReply, 10)
rpcstream := make(chan *actionnode.HealthStreamReply, 10)
c := rpcClient.StreamGo("TabletManager.HealthStream", "", rpcstream)
interrupted := false
go func() {
for {
select {
case <-ctx.Done():
// context is done
interrupted = true
close(logstream)
rpcClient.Close()
return
case hsr, ok := <-rpcstream:
if !ok {
close(logstream)
rpcClient.Close()
return
}
logstream <- hsr
}
}
}()
return logstream, func() error {
// this is only called after streaming is done
if interrupted {
return fmt.Errorf("TabletManager.HealthStreamReply interrupted by context")
}
return c.Error
}, nil
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:46,代码来源:gorpc_client.go
示例14: DialTablet
func DialTablet(addr, keyspace, shard, username, password string, encrypted bool) (TabletConn, error) {
// FIXME(sougou/shrutip): Add encrypted support
conn := new(TabletBson)
var err error
if username != "" {
conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", addr, username, password, 0)
} else {
conn.rpcClient, err = bsonrpc.DialHTTP("tcp", addr, 0)
}
if err != nil {
return nil, err
}
var sessionInfo tproto.SessionInfo
if err = conn.rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: keyspace, Shard: shard}, &sessionInfo); err != nil {
return nil, err
}
conn.session.SessionId = sessionInfo.SessionId
return conn, nil
}
开发者ID:ZhuoRoger,项目名称:vitess,代码行数:20,代码来源:tablet_bson.go
示例15: NewQueryResultReaderForTablet
// NewQueryResultReaderForTablet creates a new QueryResultReader for
// the provided tablet / sql query
func NewQueryResultReaderForTablet(ts topo.Server, tabletAlias topo.TabletAlias, sql string) (*QueryResultReader, error) {
tablet, err := ts.GetTablet(tabletAlias)
if err != nil {
return nil, err
}
addr := fmt.Sprintf("%v:%v", tablet.IPAddr, tablet.Portmap["vt"])
rpcClient, err := bsonrpc.DialHTTP("tcp", addr, 30*time.Second, nil)
if err != nil {
return nil, err
}
var sessionInfo tproto.SessionInfo
if err := rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: tablet.Keyspace, Shard: tablet.Shard}, &sessionInfo); err != nil {
return nil, err
}
req := &tproto.Query{
Sql: sql,
BindVariables: make(map[string]interface{}),
TransactionId: 0,
SessionId: sessionInfo.SessionId,
}
sr := make(chan *mproto.QueryResult, 1000)
call := rpcClient.StreamGo("SqlQuery.StreamExecute", req, sr)
// read the columns, or grab the error
cols, ok := <-sr
if !ok {
return nil, fmt.Errorf("Cannot read Fields for query: %v", sql)
}
return &QueryResultReader{
Output: sr,
Fields: cols.Fields,
client: rpcClient,
call: call,
}, nil
}
开发者ID:kingpro,项目名称:vitess,代码行数:41,代码来源:diff_utils.go
示例16: rpcCallTablet
func (client *GoRpcTabletManagerConn) rpcCallTablet(tablet *topo.TabletInfo, name string, args, reply interface{}, waitTime time.Duration) error {
// create the RPC client, using waitTime as the connect
// timeout, and starting the overall timeout as well
timer := time.After(waitTime)
rpcClient, err := bsonrpc.DialHTTP("tcp", tablet.Addr(), waitTime, nil)
if err != nil {
return fmt.Errorf("RPC error for %v: %v", tablet.Alias, err.Error())
}
defer rpcClient.Close()
// do the call in the remaining time
call := rpcClient.Go("TabletManager."+name, args, reply, nil)
select {
case <-timer:
return fmt.Errorf("Timeout waiting for TabletManager.%v to %v", name, tablet.Alias)
case <-call.Done:
if call.Error != nil {
return fmt.Errorf("Remote error for %v: %v", tablet.Alias, call.Error.Error())
} else {
return nil
}
}
}
开发者ID:chinna1986,项目名称:vitess,代码行数:23,代码来源:gorpc_client.go
示例17: dial
func (conn *Conn) dial() (err error) {
user, password, useAuth, err := conn.authCredentials()
if err != nil {
return err
}
if useAuth {
conn.rpcClient, err = bsonrpc.DialAuthHTTP("tcp", conn.dbi.Host, user, password, 0)
} else {
conn.rpcClient, err = bsonrpc.DialHTTP("tcp", conn.dbi.Host, 0)
}
if err != nil {
return
}
var sessionInfo tproto.SessionInfo
if err = conn.rpcClient.Call("SqlQuery.GetSessionId", tproto.SessionParams{Keyspace: conn.keyspace(), Shard: conn.shard()}, &sessionInfo); err != nil {
return
}
conn.SessionId = sessionInfo.SessionId
return
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:24,代码来源:tclient.go
示例18: Dial
func (client *GoRpcBinlogPlayerClient) Dial(addr string, connTimeout time.Duration) error {
var err error
client.Client, err = bsonrpc.DialHTTP("tcp", addr, connTimeout, nil)
return err
}
开发者ID:chinna1986,项目名称:vitess,代码行数:5,代码来源:player.go
示例19: Dial
func (client *client) Dial(endPoint *pb.EndPoint, connTimeout time.Duration) error {
addr := netutil.JoinHostPort(endPoint.Host, endPoint.PortMap["vt"])
var err error
client.Client, err = bsonrpc.DialHTTP("tcp", addr, connTimeout)
return err
}
开发者ID:afrolovskiy,项目名称:vitess,代码行数:6,代码来源:player.go
注:本文中的github.com/youtube/vitess/go/rpcwrap/bsonrpc.DialHTTP函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论