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
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package v2
|
|
|
|
import (
|
|
"net/http"
|
|
"path"
|
|
|
|
etcdErr "github.com/coreos/etcd/error"
|
|
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
|
)
|
|
|
|
// releaseLockHandler deletes the lock.
|
|
func (h *handler) releaseLockHandler(w http.ResponseWriter, req *http.Request) error {
|
|
h.client.SyncCluster()
|
|
|
|
vars := mux.Vars(req)
|
|
keypath := path.Join(prefix, vars["key"])
|
|
|
|
// Read index and value parameters.
|
|
index := req.FormValue("index")
|
|
value := req.FormValue("value")
|
|
if len(index) == 0 && len(value) == 0 {
|
|
return etcdErr.NewError(etcdErr.EcodeIndexOrValueRequired, "Release", 0)
|
|
} else if len(index) != 0 && len(value) != 0 {
|
|
return etcdErr.NewError(etcdErr.EcodeIndexValueMutex, "Release", 0)
|
|
}
|
|
|
|
// Look up index by value if index is missing.
|
|
if len(index) == 0 {
|
|
resp, err := h.client.Get(keypath, true, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
nodes := lockNodes{resp.Node.Nodes}
|
|
node, _ := nodes.FindByValue(value)
|
|
if node == nil {
|
|
return etcdErr.NewError(etcdErr.EcodeKeyNotFound, "Release", 0)
|
|
}
|
|
index = path.Base(node.Key)
|
|
}
|
|
|
|
// Delete the lock.
|
|
if _, err := h.client.Delete(path.Join(keypath, index), false); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|