Browse Source

Merge pull request #1612 from jonboulle/proxy

proxy: add docstrings
Jonathan Boulle 11 years ago
parent
commit
fdb82718e0
2 changed files with 14 additions and 5 deletions
  1. 5 0
      etcdserver/server.go
  2. 9 5
      proxy/proxy.go

+ 5 - 0
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")

+ 9 - 5
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)
-}