代码拉取完成,页面将自动刷新
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"
)
// setHandler attempts to set the current leader.
func (h *handler) setHandler(w http.ResponseWriter, req *http.Request) error {
vars := mux.Vars(req)
name := req.FormValue("name")
if name == "" {
return etcdErr.NewError(etcdErr.EcodeNameRequired, "Set", 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)
q.Set("ttl", req.FormValue("ttl"))
q.Set("timeout", req.FormValue("timeout"))
u.RawQuery = q.Encode()
r, err := http.NewRequest("POST", u.String(), nil)
if err != nil {
return err
}
// Close request if this connection disconnects.
closeNotifier, _ := w.(http.CloseNotifier)
stopChan := make(chan bool)
defer close(stopChan)
go func() {
select {
case <-closeNotifier.CloseNotify():
h.transport.CancelRequest(r)
case <-stopChan:
}
}()
// 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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。