github.com/jpetazzo/etcd@v0.2.1-0.20140113055439-97f1363afac5/mod/leader/v2/get_handler.go (about) 1 package v2 2 3 import ( 4 "fmt" 5 "io" 6 "net/http" 7 8 "github.com/gorilla/mux" 9 ) 10 11 // getHandler retrieves the current leader. 12 func (h *handler) getHandler(w http.ResponseWriter, req *http.Request) { 13 vars := mux.Vars(req) 14 15 // Proxy the request to the lock service. 16 url := fmt.Sprintf("%s/mod/v2/lock/%s?field=value", h.addr, vars["key"]) 17 resp, err := h.client.Get(url) 18 if err != nil { 19 http.Error(w, "read leader error: " + err.Error(), http.StatusInternalServerError) 20 return 21 } 22 defer resp.Body.Close() 23 24 if resp.StatusCode != http.StatusOK { 25 w.Write([]byte("get leader error: ")) 26 } 27 w.WriteHeader(resp.StatusCode) 28 io.Copy(w, resp.Body) 29 }