cluster.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright 2014 CoreOS, Inc.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package client
  14. import (
  15. "net/http"
  16. "net/url"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
  18. )
  19. func newHTTPClusterClient(tr *http.Transport, eps []string) (*httpClusterClient, error) {
  20. c := httpClusterClient{
  21. endpoints: make([]*httpClient, len(eps)),
  22. }
  23. for i, ep := range eps {
  24. u, err := url.Parse(ep)
  25. if err != nil {
  26. return nil, err
  27. }
  28. c.endpoints[i] = &httpClient{
  29. transport: tr,
  30. endpoint: *u,
  31. }
  32. }
  33. return &c, nil
  34. }
  35. type httpClusterClient struct {
  36. endpoints []*httpClient
  37. }
  38. func (c *httpClusterClient) do(ctx context.Context, act httpAction) (int, []byte, error) {
  39. //TODO(bcwaldon): introduce retry logic so all endpoints are attempted
  40. return c.endpoints[0].do(ctx, act)
  41. }