本文整理汇总了Golang中github.com/coreos/etcd/Godeps/_workspace/src/google/golang.org/grpc.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dial函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: leaseCreateCommandFunc
// leaseCreateCommandFunc executes the "lease create" command.
func leaseCreateCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("lease create command needs TTL argument."))
}
ttl, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
ExitWithError(ExitBadArgs, fmt.Errorf("bad TTL (%v)", err))
}
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
lease := pb.NewLeaseClient(conn)
req := &pb.LeaseCreateRequest{TTL: ttl}
resp, err := lease.LeaseCreate(context.Background(), req)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create lease (%v)\n", err)
return
}
fmt.Printf("lease %016x created with TTL(%ds)\n", resp.ID, resp.TTL)
}
开发者ID:Timer,项目名称:etcd,代码行数:29,代码来源:lease_command.go
示例2: memberListCommandFunc
// memberListCommandFunc executes the "member list" command.
func memberListCommandFunc(cmd *cobra.Command, args []string) {
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
mc := pb.NewClusterClient(conn)
resp, err := mc.MemberList(context.TODO(), &pb.MemberListRequest{})
if err != nil {
ExitWithError(ExitError, err)
}
// use https://github.com/olekukonko/tablewriter to print out a pretty table?
for _, m := range resp.Members {
if len(m.Name) == 0 {
fmt.Printf("%16x[unstarted]: peerURLs=%s\n", m.ID, strings.Join(m.PeerURLs, ","))
} else {
fmt.Printf("%16x: name=%s peerURLs=%s clientURLs=%s\n", m.ID, m.Name, strings.Join(m.PeerURLs, ","), strings.Join(m.ClientURLs, ","))
}
}
}
开发者ID:rtewalt,项目名称:etcd,代码行数:26,代码来源:member_command.go
示例3: memberUpdateCommandFunc
// memberUpdateCommandFunc executes the "member update" command.
func memberUpdateCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("member ID is not provided"))
}
id, err := strconv.ParseUint(args[0], 16, 64)
if err != nil {
ExitWithError(ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err))
}
if len(memberPeerURLs) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided."))
}
urls := strings.Split(memberPeerURLs, ",")
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
mc := pb.NewClusterClient(conn)
resp, err := mc.MemberUpdate(context.TODO(), &pb.MemberUpdateRequest{ID: uint64(id), PeerURLs: urls})
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Member %16x updated in cluster %16x\n", id, resp.Header.ClusterId)
}
开发者ID:rtewalt,项目名称:etcd,代码行数:34,代码来源:member_command.go
示例4: memberRemoveCommandFunc
// memberRemoveCommandFunc executes the "member remove" command.
func memberRemoveCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("member ID is not provided"))
}
id, err := strconv.ParseUint(args[0], 16, 64)
if err != nil {
ExitWithError(ExitBadArgs, fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err))
}
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
mc := pb.NewClusterClient(conn)
resp, err := mc.MemberRemove(context.TODO(), &pb.MemberRemoveRequest{ID: uint64(id)})
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Member %16x removed from cluster %16x\n", id, resp.Header.ClusterId)
}
开发者ID:rtewalt,项目名称:etcd,代码行数:28,代码来源:member_command.go
示例5: leaseRevokeCommandFunc
// leaseRevokeCommandFunc executes the "lease create" command.
func leaseRevokeCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("lease revoke command needs 1 argument"))
}
id, err := strconv.ParseInt(args[0], 16, 64)
if err != nil {
ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err))
}
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
lease := pb.NewLeaseClient(conn)
req := &pb.LeaseRevokeRequest{ID: id}
_, err = lease.LeaseRevoke(context.Background(), req)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to revoke lease (%v)\n", err)
return
}
fmt.Printf("lease %016x revoked\n", id)
}
开发者ID:Timer,项目名称:etcd,代码行数:29,代码来源:lease_command.go
示例6: clientSetUp
func clientSetUp(t *testing.T, addr string, cg grpc.CompressorGenerator, dg grpc.DecompressorGenerator, ua string, e env) (cc *grpc.ClientConn) {
var derr error
if e.security == "tls" {
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com")
if err != nil {
t.Fatalf("Failed to create credentials %v", err)
}
cc, derr = grpc.Dial(addr, grpc.WithTransportCredentials(creds), grpc.WithDialer(e.dialer), grpc.WithUserAgent(ua), grpc.WithCompressor(cg), grpc.WithDecompressor(dg))
} else {
cc, derr = grpc.Dial(addr, grpc.WithDialer(e.dialer), grpc.WithInsecure(), grpc.WithUserAgent(ua), grpc.WithCompressor(cg), grpc.WithDecompressor(dg))
}
if derr != nil {
t.Fatalf("Dial(%q) = %v", addr, derr)
}
return
}
开发者ID:rtewalt,项目名称:etcd,代码行数:16,代码来源:end2end_test.go
示例7: txnCommandFunc
// txnCommandFunc executes the "txn" command.
func txnCommandFunc(c *cli.Context) {
if len(c.Args()) != 0 {
panic("unexpected args")
}
reader := bufio.NewReader(os.Stdin)
next := compareState
txn := &pb.TxnRequest{}
for next != nil {
next = next(txn, reader)
}
conn, err := grpc.Dial("127.0.0.1:12379")
if err != nil {
panic(err)
}
etcd := pb.NewEtcdClient(conn)
resp, err := etcd.Txn(context.Background(), txn)
if err != nil {
fmt.Println(err)
}
if resp.Succeeded {
fmt.Println("executed success request list")
} else {
fmt.Println("executed failure request list")
}
}
开发者ID:royxhl,项目名称:etcd,代码行数:30,代码来源:txn_command.go
示例8: txnCommandFunc
// txnCommandFunc executes the "txn" command.
func txnCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("txn command does not accept argument."))
}
reader := bufio.NewReader(os.Stdin)
next := compareState
txn := &pb.TxnRequest{}
for next != nil {
next = next(txn, reader)
}
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
kv := pb.NewKVClient(conn)
resp, err := kv.Txn(context.Background(), txn)
if err != nil {
ExitWithError(ExitError, err)
}
if resp.Succeeded {
fmt.Println("executed success request list")
} else {
fmt.Println("executed failure request list")
}
}
开发者ID:ikatson,项目名称:etcd,代码行数:34,代码来源:txn_command.go
示例9: deleteRangeCommandFunc
// deleteRangeCommandFunc executes the "deleteRange" command.
func deleteRangeCommandFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("delete-range command needs arguments."))
}
var rangeEnd []byte
key := []byte(args[0])
if len(args) > 1 {
rangeEnd = []byte(args[1])
}
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
kv := pb.NewKVClient(conn)
req := &pb.DeleteRangeRequest{Key: key, RangeEnd: rangeEnd}
kv.DeleteRange(context.Background(), req)
if rangeEnd != nil {
fmt.Printf("range [%s, %s) is deleted\n", string(key), string(rangeEnd))
} else {
fmt.Printf("key %s is deleted\n", string(key))
}
}
开发者ID:ikatson,项目名称:etcd,代码行数:31,代码来源:delete_range_command.go
示例10: putCommandFunc
// putCommandFunc executes the "put" command.
func putCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 2 {
ExitWithError(ExitBadArgs, fmt.Errorf("put command needs 2 arguments."))
}
id, err := strconv.ParseInt(leaseStr, 16, 64)
if err != nil {
ExitWithError(ExitBadArgs, fmt.Errorf("bad lease ID arg (%v), expecting ID in Hex", err))
}
key := []byte(args[0])
value := []byte(args[1])
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
kv := pb.NewKVClient(conn)
req := &pb.PutRequest{Key: key, Value: value, Lease: id}
kv.Put(context.Background(), req)
fmt.Printf("%s %s\n", key, value)
}
开发者ID:Timer,项目名称:etcd,代码行数:28,代码来源:put_command.go
示例11: NewClientConn
// NewClientConn creates a gRPC client connection to addr.
func NewClientConn(addr string) *grpc.ClientConn {
conn, err := grpc.Dial(addr)
if err != nil {
grpclog.Fatalf("NewClientConn(%q) failed to create a ClientConn %v", addr, err)
}
return conn
}
开发者ID:ikatson,项目名称:etcd,代码行数:8,代码来源:benchmark.go
示例12: deleteRangeCommandFunc
// deleteRangeCommandFunc executes the "delegeRange" command.
func deleteRangeCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
panic("bad arg")
}
var rangeEnd []byte
key := []byte(c.Args()[0])
if len(c.Args()) > 1 {
rangeEnd = []byte(c.Args()[1])
}
conn, err := grpc.Dial(c.GlobalString("endpoint"))
if err != nil {
panic(err)
}
etcd := pb.NewEtcdClient(conn)
req := &pb.DeleteRangeRequest{Key: key, RangeEnd: rangeEnd}
etcd.DeleteRange(context.Background(), req)
if rangeEnd != nil {
fmt.Printf("range [%s, %s) is deleted\n", string(key), string(rangeEnd))
} else {
fmt.Printf("key %s is deleted\n", string(key))
}
}
开发者ID:carriercomm,项目名称:etcd,代码行数:26,代码来源:delete_range_command.go
示例13: memberAddCommandFunc
// memberAddCommandFunc executes the "member add" command.
func memberAddCommandFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("member name not provided."))
}
if len(memberPeerURLs) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided."))
}
urls := strings.Split(memberPeerURLs, ",")
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
mc := pb.NewClusterClient(conn)
resp, err := mc.MemberAdd(context.TODO(), &pb.MemberAddRequest{PeerURLs: urls})
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Member %16x added to cluster %16x\n", args[0], resp.Member.ID, resp.Header.ClusterId)
}
开发者ID:rtewalt,项目名称:etcd,代码行数:29,代码来源:member_command.go
示例14: NewClientV3
// NewClientV3 creates a new grpc client connection to the member
func NewClientV3(m *member) (*clientv3.Client, error) {
if m.grpcAddr == "" {
return nil, fmt.Errorf("member not configured for grpc")
}
f := func(a string, t time.Duration) (net.Conn, error) {
return net.Dial("unix", a)
}
unixdialer := grpc.WithDialer(f)
opts := []grpc.DialOption{
unixdialer,
grpc.WithBlock(),
grpc.WithTimeout(5 * time.Second)}
if m.ClientTLSInfo != nil {
tlscfg, err := m.ClientTLSInfo.ClientConfig()
if err != nil {
return nil, err
}
creds := credentials.NewTLS(tlscfg)
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
opts = append(opts, grpc.WithInsecure())
}
conn, err := grpc.Dial(m.grpcAddr, opts...)
if err != nil {
return nil, err
}
return clientv3.NewFromConn(conn), nil
}
开发者ID:pugna0,项目名称:etcd,代码行数:29,代码来源:cluster.go
示例15: Dial
// Dial establishes a connection for a given endpoint using the client's config
func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error) {
opts := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithTimeout(c.cfg.DialTimeout),
}
if c.creds != nil {
opts = append(opts, grpc.WithTransportCredentials(*c.creds))
} else {
opts = append(opts, grpc.WithInsecure())
}
if url, uerr := url.Parse(endpoint); uerr == nil && url.Scheme == "unix" {
f := func(a string, t time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", a, t)
}
// strip unix:// prefix so certs work
endpoint = url.Host
opts = append(opts, grpc.WithDialer(f))
}
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return nil, err
}
return conn, nil
}
开发者ID:obeattie,项目名称:etcd,代码行数:26,代码来源:client.go
示例16: rangeCommandFunc
// rangeCommandFunc executes the "range" command.
func rangeCommandFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 {
ExitWithError(ExitBadArgs, fmt.Errorf("range command needs arguments."))
}
var rangeEnd []byte
key := []byte(args[0])
if len(args) > 1 {
rangeEnd = []byte(args[1])
}
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
conn, err := grpc.Dial(endpoint)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
kv := pb.NewKVClient(conn)
req := &pb.RangeRequest{Key: key, RangeEnd: rangeEnd}
resp, err := kv.Range(context.Background(), req)
for _, kv := range resp.Kvs {
fmt.Printf("%s %s\n", string(kv.Key), string(kv.Value))
}
}
开发者ID:ikatson,项目名称:etcd,代码行数:28,代码来源:range_command.go
示例17: Dial
// Dial establishes a connection for a given endpoint using the client's config
func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error) {
opts := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithTimeout(c.cfg.DialTimeout),
}
if c.creds != nil {
opts = append(opts, grpc.WithTransportCredentials(*c.creds))
} else {
opts = append(opts, grpc.WithInsecure())
}
proto := "tcp"
if url, uerr := url.Parse(endpoint); uerr == nil && url.Scheme == "unix" {
proto = "unix"
// strip unix:// prefix so certs work
endpoint = url.Host
}
f := func(a string, t time.Duration) (net.Conn, error) {
select {
case <-c.ctx.Done():
return nil, c.ctx.Err()
default:
}
return net.DialTimeout(proto, a, t)
}
opts = append(opts, grpc.WithDialer(f))
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return nil, err
}
return conn, nil
}
开发者ID:lrita,项目名称:etcd,代码行数:34,代码来源:client.go
示例18: checkConsistency
// checkConsistency stops the cluster for a moment and get the hashes of KV storages.
func (c *cluster) checkConsistency() error {
hashes := make(map[string]uint32)
for _, u := range c.GRPCURLs {
conn, err := grpc.Dial(u, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second))
if err != nil {
return err
}
kvc := pb.NewKVClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
resp, err := kvc.Hash(ctx, &pb.HashRequest{})
hv := resp.Hash
if resp != nil && err != nil {
return err
}
cancel()
hashes[u] = hv
}
if !checkConsistency(hashes) {
return fmt.Errorf("check consistency fails: %v", hashes)
}
return nil
}
开发者ID:Longbow98,项目名称:etcd,代码行数:26,代码来源:tester.go
示例19: main
func main() {
var (
c, n int
url string
size int
)
flag.IntVar(&c, "c", 50, "number of connections")
flag.IntVar(&n, "n", 200, "number of requests")
flag.IntVar(&size, "s", 128, "size of put request")
// TODO: config the number of concurrency in each connection
flag.StringVar(&url, "u", "127.0.0.1:12379", "etcd server endpoint")
flag.Parse()
if flag.NArg() < 1 {
flag.Usage()
os.Exit(1)
}
var act string
if act = flag.Args()[0]; act != "get" && act != "put" {
fmt.Printf("unsupported action %v\n", act)
os.Exit(1)
}
conn, err := grpc.Dial(url)
if err != nil {
fmt.Errorf("dial error: %v", err)
os.Exit(1)
}
results = make(chan *result, n)
bar = pb.New(n)
bar.Format("Bom !")
bar.Start()
start := time.Now()
if act == "get" {
var rangeEnd []byte
key := []byte(flag.Args()[1])
if len(flag.Args()) > 2 {
rangeEnd = []byte(flag.Args()[2])
}
benchGet(conn, key, rangeEnd, n, c)
} else if act == "put" {
key := []byte(flag.Args()[1])
// number of different keys to put into etcd
kc, err := strconv.ParseInt(flag.Args()[2], 10, 32)
if err != nil {
panic(err)
}
benchPut(conn, key, int(kc), n, c, size)
}
wg.Wait()
bar.Finish()
printReport(n, results, time.Now().Sub(start))
}
开发者ID:carriercomm,项目名称:etcd,代码行数:59,代码来源:main.go
示例20: setUp
func setUp(maxStream uint32, e env) (s *grpc.Server, cc *grpc.ClientConn) {
sopts := []grpc.ServerOption{grpc.MaxConcurrentStreams(maxStream)}
la := ":0"
switch e.network {
case "unix":
la = "/tmp/testsock" + fmt.Sprintf("%d", time.Now())
syscall.Unlink(la)
}
lis, err := net.Listen(e.network, la)
if err != nil {
grpclog.Fatalf("Failed to listen: %v", err)
}
if e.security == "tls" {
creds, err := credentials.NewServerTLSFromFile(tlsDir+"server1.pem", tlsDir+"server1.key")
if err != nil {
grpclog.Fatalf("Failed to generate credentials %v", err)
}
sopts = append(sopts, grpc.Creds(creds))
}
s = grpc.NewServer(sopts...)
testpb.RegisterTestServiceServer(s, &testServer{})
go s.Serve(lis)
addr := la
switch e.network {
case "unix":
default:
_, port, err := net.SplitHostPort(lis.Addr().String())
if err != nil {
grpclog.Fatalf("Failed to parse listener address: %v", err)
}
addr = "localhost:" + port
}
if e.security == "tls" {
creds, err := credentials.NewClientTLSFromFile(tlsDir+"ca.pem", "x.test.youtube.com")
if err != nil {
grpclog.Fatalf("Failed to create credentials %v", err)
}
cc, err = grpc.Dial(addr, grpc.WithTransportCredentials(creds), grpc.WithDialer(e.dialer))
} else {
cc, err = grpc.Dial(addr, grpc.WithDialer(e.dialer))
}
if err != nil {
grpclog.Fatalf("Dial(%q) = %v", addr, err)
}
return
}
开发者ID:CNDonny,项目名称:scope,代码行数:46,代码来源:end2end_test.go
注:本文中的github.com/coreos/etcd/Godeps/_workspace/src/google/golang.org/grpc.Dial函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论