mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

for i in github.com/BurntSushi/toml github.com/coreos/go-etcd/etcd github.com/coreos/go-log/log github.com/gorilla/context github.com/rcrowley/go-metrics bitbucket.org/kardianos/osext github.com/coreos/go-systemd/journal github.com/coreos/raft code.google.com/p/goprotobuf/proto ; do goven -copy -rewrite $i; done
46 lines
921 B
Go
46 lines
921 B
Go
package v2
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
etcdErr "github.com/coreos/etcd/error"
|
|
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
|
)
|
|
|
|
// deleteHandler remove a given leader.
|
|
func (h *handler) deleteHandler(w http.ResponseWriter, req *http.Request) error {
|
|
vars := mux.Vars(req)
|
|
name := req.FormValue("name")
|
|
if name == "" {
|
|
return etcdErr.NewError(etcdErr.EcodeNameRequired, "Delete", 0)
|
|
}
|
|
|
|
// Proxy the request to the the lock service.
|
|
u, err := url.Parse(fmt.Sprintf("%s/mod/v2/lock/%s", h.addr, vars["key"]))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
q := u.Query()
|
|
q.Set("value", name)
|
|
u.RawQuery = q.Encode()
|
|
|
|
r, err := http.NewRequest("DELETE", u.String(), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Read from the leader lock.
|
|
resp, err := h.client.Do(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
w.WriteHeader(resp.StatusCode)
|
|
io.Copy(w, resp.Body)
|
|
|
|
return nil
|
|
}
|