diff --git a/etcdserver/server.go b/etcdserver/server.go index f526a2f5a..fac0c111c 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -690,6 +690,11 @@ func (s *EtcdServer) snapshot(snapi uint64, snapnodes []uint64) { } } +// GetClusterFromPeers takes a set of URLs representing etcd peers, and +// attempts to construct a Cluster by accessing the members endpoint on one of +// these URLs. The first URL to provide a response is used. If no URLs provide +// a response, or a Cluster cannot be successfully created from a received +// response, an error is returned. func GetClusterFromPeers(urls []string) (*Cluster, error) { for _, u := range urls { resp, err := http.Get(u + "/members") diff --git a/proxy/proxy.go b/proxy/proxy.go index 10d26face..619524040 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -26,6 +26,9 @@ import ( // backends. type GetProxyURLs func() []string +// NewHandler creates a new HTTP handler, listening on the given transport, +// which will proxy requests to an etcd cluster. +// The handler will periodically update its view of the cluster. func NewHandler(t *http.Transport, urlsFunc GetProxyURLs) http.Handler { return &reverseProxy{ director: newDirector(urlsFunc), @@ -33,6 +36,12 @@ func NewHandler(t *http.Transport, urlsFunc GetProxyURLs) http.Handler { } } +// NewReadonlyHandler wraps the given HTTP handler to allow only GET requests +func NewReadonlyHandler(hdlr http.Handler) http.Handler { + readonly := readonlyHandlerFunc(hdlr) + return http.HandlerFunc(readonly) +} + func readonlyHandlerFunc(next http.Handler) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, req *http.Request) { if req.Method != "GET" { @@ -43,8 +52,3 @@ func readonlyHandlerFunc(next http.Handler) func(http.ResponseWriter, *http.Requ next.ServeHTTP(w, req) } } - -func NewReadonlyHandler(hdlr http.Handler) http.Handler { - readonly := readonlyHandlerFunc(hdlr) - return http.HandlerFunc(readonly) -}