doc.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2016 CoreOS, Inc.
  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. // clientv3 is 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:12378", "localhost:22378", "localhost:32378"},
  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. // etcd client returns 2 types of errors:
  41. //
  42. // 1. context error: canceled or deadline exceeded.
  43. // 2. gRPC error: see https://github.com/coreos/etcd/blob/master/etcdserver/api/v3rpc/error.go.
  44. //
  45. // Here is the example code to handle client errors:
  46. //
  47. // resp, err := kvc.Put(ctx, "", "")
  48. // if err != nil {
  49. // if err == context.Canceled {
  50. // // ctx is canceled by another routine
  51. // } else if err == context.DeadlineExceeded {
  52. // // ctx is attached with a deadline and it exceeded
  53. // } else if verr, ok := err.(*v3rpc.ErrEmptyKey); ok {
  54. // // process (verr.Errors)
  55. // } else {
  56. // // bad cluster endpoints, which are not etcd servers
  57. // }
  58. // }
  59. //
  60. package clientv3