doc.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // Package naming provides an etcd-backed gRPC resolver for discovering gRPC services.
  15. //
  16. // To use, first import the packages:
  17. //
  18. // import (
  19. // "go.etcd.io/etcd/clientv3"
  20. // etcdnaming "go.etcd.io/etcd/clientv3/naming"
  21. //
  22. // "google.golang.org/grpc"
  23. // "google.golang.org/grpc/naming"
  24. // )
  25. //
  26. // First, register new endpoint addresses for a service:
  27. //
  28. // func etcdAdd(c *clientv3.Client, service, addr string) error {
  29. // r := &etcdnaming.GRPCResolver{Client: c}
  30. // return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr})
  31. // }
  32. //
  33. // Dial an RPC service using the etcd gRPC resolver and a gRPC Balancer:
  34. //
  35. // func etcdDial(c *clientv3.Client, service string) (*grpc.ClientConn, error) {
  36. // r := &etcdnaming.GRPCResolver{Client: c}
  37. // b := grpc.RoundRobin(r)
  38. // return grpc.Dial(service, grpc.WithBalancer(b))
  39. // }
  40. //
  41. // Optionally, force delete an endpoint:
  42. //
  43. // func etcdDelete(c *clientv3, service, addr string) error {
  44. // r := &etcdnaming.GRPCResolver{Client: c}
  45. // return r.Update(c.Ctx(), service, naming.Update{Op: naming.Delete, Addr: "1.2.3.4"})
  46. // }
  47. //
  48. // Or register an expiring endpoint with a lease:
  49. //
  50. // func etcdLeaseAdd(c *clientv3.Client, lid clientv3.LeaseID, service, addr string) error {
  51. // r := &etcdnaming.GRPCResolver{Client: c}
  52. // return r.Update(c.Ctx(), service, naming.Update{Op: naming.Add, Addr: addr}, clientv3.WithLease(lid))
  53. // }
  54. //
  55. package naming