doc.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2016 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 clientv3 implements the official Go etcd client for v3.
  15. //
  16. // Create client using `clientv3.New`:
  17. //
  18. // cli, err := clientv3.New(clientv3.Config{
  19. // Endpoints: []string{"localhost:2379", "localhost:22379", "localhost:32379"},
  20. // DialTimeout: 5 * time.Second,
  21. // })
  22. // if err != nil {
  23. // // handle error!
  24. // }
  25. // defer cli.Close()
  26. //
  27. // Make sure to close the client after using it. If the client is not closed, the
  28. // connection will have leaky goroutines.
  29. //
  30. // To specify client request timeout, pass context.WithTimeout to APIs:
  31. //
  32. // ctx, cancel := context.WithTimeout(context.Background(), timeout)
  33. // resp, err := kvc.Put(ctx, "sample_key", "sample_value")
  34. // cancel()
  35. // if err != nil {
  36. // // handle error!
  37. // }
  38. // // use the response
  39. //
  40. // The Client has internal state (watchers and leases), so Clients should be reused instead of created as needed.
  41. // Clients are safe for concurrent use by multiple goroutines.
  42. //
  43. // etcd client returns 2 types of errors:
  44. //
  45. // 1. context error: canceled or deadline exceeded.
  46. // 2. gRPC error: see https://github.com/coreos/etcd/blob/master/etcdserver/api/v3rpc/error.go.
  47. //
  48. // Here is the example code to handle client errors:
  49. //
  50. // resp, err := kvc.Put(ctx, "", "")
  51. // if err != nil {
  52. // if err == context.Canceled {
  53. // // ctx is canceled by another routine
  54. // } else if err == context.DeadlineExceeded {
  55. // // ctx is attached with a deadline and it exceeded
  56. // } else if verr, ok := err.(*v3rpc.ErrEmptyKey); ok {
  57. // // process (verr.Errors)
  58. // } else {
  59. // // bad cluster endpoints, which are not etcd servers
  60. // }
  61. // }
  62. //
  63. package clientv3