example_maintenance_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_test
  15. import (
  16. "context"
  17. "fmt"
  18. "log"
  19. "go.etcd.io/etcd/clientv3"
  20. )
  21. func ExampleMaintenance_status() {
  22. for _, ep := range endpoints {
  23. cli, err := clientv3.New(clientv3.Config{
  24. Endpoints: []string{ep},
  25. DialTimeout: dialTimeout,
  26. })
  27. if err != nil {
  28. log.Fatal(err)
  29. }
  30. defer cli.Close()
  31. resp, err := cli.Status(context.Background(), ep)
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. fmt.Printf("endpoint: %s / Leader: %v\n", ep, resp.Header.MemberId == resp.Leader)
  36. }
  37. // endpoint: localhost:2379 / Leader: false
  38. // endpoint: localhost:22379 / Leader: false
  39. // endpoint: localhost:32379 / Leader: true
  40. }
  41. func ExampleMaintenance_defragment() {
  42. for _, ep := range endpoints {
  43. cli, err := clientv3.New(clientv3.Config{
  44. Endpoints: []string{ep},
  45. DialTimeout: dialTimeout,
  46. })
  47. if err != nil {
  48. log.Fatal(err)
  49. }
  50. defer cli.Close()
  51. if _, err = cli.Defragment(context.TODO(), ep); err != nil {
  52. log.Fatal(err)
  53. }
  54. }
  55. }