go.etcd.io/etcd@v3.3.27+incompatible/clientv3/naming/doc.go (about) 1 // Copyright 2017 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package naming provides an etcd-backed gRPC resolver for discovering gRPC services. 16 // 17 // To use, first import the packages: 18 // 19 // import ( 20 // "github.com/coreos/etcd/clientv3" 21 // etcdnaming "github.com/coreos/etcd/clientv3/naming" 22 // 23 // "google.golang.org/grpc" 24 // "google.golang.org/grpc/naming" 25 // ) 26 // 27 // First, register new endpoint addresses for a service: 28 // 29 // func etcdAdd(c *clientv3.Client, service, addr string) error { 30 // r := &etcdnaming.GRPCResolver{Client: c} 31 // return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}) 32 // } 33 // 34 // Dial an RPC service using the etcd gRPC resolver and a gRPC Balancer: 35 // 36 // func etcdDial(c *clientv3.Client, service string) (*grpc.ClientConn, error) { 37 // r := &etcdnaming.GRPCResolver{Client: c} 38 // b := grpc.RoundRobin(r) 39 // return grpc.Dial(service, grpc.WithBalancer(b)) 40 // } 41 // 42 // Optionally, force delete an endpoint: 43 // 44 // func etcdDelete(c *clientv3, service, addr string) error { 45 // r := &etcdnaming.GRPCResolver{Client: c} 46 // return r.Update(c.Ctx(), "my-service", naming.Update{Op: naming.Delete, Addr: "1.2.3.4"}) 47 // } 48 // 49 // Or register an expiring endpoint with a lease: 50 // 51 // func etcdLeaseAdd(c *clientv3.Client, lid clientv3.LeaseID, service, addr string) error { 52 // r := &etcdnaming.GRPCResolver{Client: c} 53 // return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}, clientv3.WithLease(lid)) 54 // } 55 // 56 package naming