當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Engine.CheckConnectionErr方法代碼示例

本文整理匯總了Golang中github.com/docker/swarm/cluster.Engine.CheckConnectionErr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.CheckConnectionErr方法的具體用法?Golang Engine.CheckConnectionErr怎麽用?Golang Engine.CheckConnectionErr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/docker/swarm/cluster.Engine的用法示例。


在下文中一共展示了Engine.CheckConnectionErr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: proxyNetworkDisconnect

// POST /networks/{networkid:.*}/disconnect
func proxyNetworkDisconnect(c *context, w http.ResponseWriter, r *http.Request) {
	var networkid = mux.Vars(r)["networkid"]
	network := c.cluster.Networks().Uniq().Get(networkid)
	if network == nil {
		httpError(w, fmt.Sprintf("No such network: %s", networkid), http.StatusNotFound)
		return
	}
	// Set the network ID in the proxied URL path.
	r.URL.Path = strings.Replace(r.URL.Path, networkid, network.ID, 1)

	// make a copy of r.Body
	buf, _ := ioutil.ReadAll(r.Body)
	bodyCopy := ioutil.NopCloser(bytes.NewBuffer(buf))
	defer bodyCopy.Close()
	// restore r.Body stream as it'll be read again
	r.Body = ioutil.NopCloser(bytes.NewBuffer(buf))

	// Extract container info from r.Body copy
	var disconnect apitypes.NetworkDisconnect
	if err := json.NewDecoder(bodyCopy).Decode(&disconnect); err != nil {
		httpError(w, fmt.Sprintf("Container is not specified"), http.StatusNotFound)
		return
	}

	var engine *cluster.Engine

	if disconnect.Force && network.Scope == "global" {
		randomEngine, err := c.cluster.RANDOMENGINE()
		if err != nil {
			httpError(w, err.Error(), http.StatusInternalServerError)
			return
		}
		engine = randomEngine
	} else {
		container := c.cluster.Container(disconnect.Container)
		if container == nil {
			httpError(w, fmt.Sprintf("No such container: %s", disconnect.Container), http.StatusNotFound)
			return
		}
		engine = container.Engine
	}

	cb := func(resp *http.Response) {
		// force fresh networks on this engine
		engine.RefreshNetworks()
	}

	// request is forwarded to the container's address
	err := proxyAsync(engine, w, r, cb)
	engine.CheckConnectionErr(err)
	if err != nil {
		httpError(w, err.Error(), http.StatusNotFound)
	}
}
開發者ID:yehohanan7,項目名稱:swarm,代碼行數:55,代碼來源:handlers.go


注:本文中的github.com/docker/swarm/cluster.Engine.CheckConnectionErr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。